if i give the value of *this as a default argument, i get following error on MSVC .Net 2003:Code:#include <iostream> #include <string> #include <cctype> using namespace std; class mystring : public string { public: mystring& lower_case(mystring& str=*this) { for (int i=0; i<str.size(); i++) { if (isupper(str[i])) { str[i] = tolower(str[i]); } } return str; } mystring& upper_case(mystring& str=*this) { for (int i=0; i<str.size(); i++) { if (islower(str[i])) { str[i] = toupper(str[i]); } } return str; } }; int main() { mystring str; while (true) { cout << "String: "; getline(cin, str, '\n'); if (str == "$") break; cout << "Upper case: " << str.upper_case(str) << endl; cout << "Lower case: " << str.lower_case(str) << endl; } return 0; }
Code:C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(574) : wa rning C4530: C++ exception handler used, but unwind semantics are not enabled. S pecify /EHsc C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\istream(828) : wa rning C4530: C++ exception handler used, but unwind semantics are not enabled. S pecify /EHsc C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\istream(1064) : w arning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc case.cpp(9) : error C2355: 'this' : can only be referenced inside non-static mem ber functions case.cpp(21) : error C2355: 'this' : can only be referenced inside non-static me mber functions



