#include <iostream>
class MyClass {
char& operator[]( index_type );
typedef int index_type; // Error
};
int main(){
MyClass obj;
return 0;
}
#include <iostream>
class MyClass {
public:
typedef int index_type;
char& operator[]( index_type elem ){ return _string[elem]; }
private:
char* _string;
};
int main(){
MyClass obj;
return 0;
}
#include <iostream>
class MyClass {
public:
typedef int index_type;
char& operator[]( index_type);
private:
char* _string;
};
char& MyClass::operator[]( index_type elem ){ return _string[elem]; }
int main(){
MyClass obj;
return 0;
}
#include <iostream>
class Account {
typedef double Money; //type definition can also be private
private:
static Money _interestRate;
static Money initInterest(Money);
};
// The return type Money must be qualified by qualifier
Account::Money Account::initInterest(Money m){
_interestRate = m;
return _interestRate;
}
// everything following the name of the static member
// _interestRate until the semicolon ending
// the static member definition is
// in the scope of class Account.
Account::Money Account::_interestRate = initInterest(1.2);
int main(){
Account obj;
return 0;
}
#include <iostream>
class Account {
public:
typedef double Money;
Money _interestRate;
Money initInterest(Money);
};
Account::Money Account::initInterest(Money m){
_interestRate = m;
return _interestRate;
}
int main(){
Account obj;
std::cout << obj.initInterest(1.2) << std::endl;
return 0;
}