#include <iostream>
using namespace std;
class A {
typedef int myInt;
int k;
public:
A(int i) : k(i) {}
myInt getK();
};
myInt A::getK() { return k; }
int main (int argc, char * const argv[]) {
A a(5);
cout << a.getK() << endl;
return 0;
}
myInt is not recognized by the compiler as an ‘int’ in this line:
myInt A::getK() { return k; }
How can I get the compiler to recognize myInt as int?
typedefcreates synonyms, not new types, somyIntandintare already the same. The problem is scope — there is nomyIntin a global scope, you have to useA::myIntoutside of the class.