Reputation: 211
can anyone please tell me the mistake in the below program.
#include <iostream>
using namespace std;
class A
{
public:
typedef int count;
static count cnt ;
};
count A::cnt = 0;
int main()
{
return 0;
}
count does not name a type
Upvotes: 4
Views: 323
Reputation: 234785
You would have to use A::count A::cnt = 0;
as your typedef is defined within the scope of class A.
i.e. either move the typedef outside the class or use scope resolution as above.
Upvotes: 13
Reputation: 13207
Your typedef
is inside your class and as such not globally available.
You would need to
#include <iostream>
using namespace std;
typedef int count;
class A
{
public:
static count cnt ;
};
count A::cnt = 0;
int main()
{
return 0;
}
Upvotes: 2