Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to assign typedef variables as static

Tags:

c++

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;
}

error

count does not name a type

like image 240
user2413497 Avatar asked Dec 06 '22 07:12

user2413497


2 Answers

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.

like image 114
Bathsheba Avatar answered Dec 15 '22 11:12

Bathsheba


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;
}
like image 22
bash.d Avatar answered Dec 15 '22 10:12

bash.d