why we can't declare a static variable incide local class(class inside a function) ?
Neelam_1
0
Newbie Poster
Recommended Answers
Jump to PostYou can, but static data member definition isn't exactly intuitive without a fairly good understanding of the object model:
class outside { public: class inside { public: static int x; // Declare as normal }; }; // Define using name resolution int outside::inside::x = 123;
Jump to Post@deceptikon: You misunderstood what the OP was referring to. She is referring to a local class, not a nested class. In other words, this is the case in question:
void f() { class inside { public: static int x; // Forbidden! }; };
And the explanation …
All 5 Replies
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
mike_2000_17
2,669
21st Century Viking
Team Colleague
Featured Poster
rubberman
1,355
Nearly a Posting Virtuoso
Featured Poster
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
Neelam_1
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.