#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 'int' in this line:
myInt A::getK() { return k; }
How can I make the compiler recognize myInt as int?
typedef creates synonyms, not new types, so myInt and int already the same. The problem is in scope - there is no myInt in the global myInt , you must use A::myInt outside the class.
typedef
myInt
int
A::myInt
A::myInt A::getK() { return k; }
You must define the typedef type because you created it inside scope A
A
Put the definition outside the class.