How to assign typedef variables as static

Can someone tell me the error in the program below.

#include <iostream> using namespace std; class A { public: typedef int count; static count cnt ; }; count A::cnt = 0; int main() { return 0; } 

Error

count does not name type

+4
source share
2 answers

You will need to use A::count A::cnt = 0; since your typedef is defined within class A.

i.e. either move the typedef outside the class, or use the scope resolution as above.

+13
source

Your typedef is inside your class and as such is not available in the world.

You need

 #include <iostream> using namespace std; typedef int count; class A { public: static count cnt ; }; count A::cnt = 0; int main() { return 0; } 
+2
source

Source: https://habr.com/ru/post/1483529/


All Articles