[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppStatic
A common use of static is when you want to keep track of how many instances a class has:
A good example of a static variable in a function is here.
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppStatic
(C++) static
Keyword enabling in-class or in-function static variables.A common use of static is when you want to keep track of how many instances a class has:
class InstanceCounter { static int mNinstances; public: InstanceCounter() { ++mNinstances; std::cout << "Constructed an instance." << "Now there are " << mNinstances << "." << std::endl; } ~InstanceCounter() { --mNinstances; std::cout << "Destructed an instance." << "Now there are " << mNinstances << "." << std::endl; } }; int InstanceCounter::mNinstances = 0; int main() { InstanceCounter one, two, three, four,five; }
- include <iostream>
A good example of a static variable in a function is here.
Code links
'static' links
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
