Private Global Variable to Class?

Hey guys I want to make a destructor counter...So it needs to be outside that specific instance of the class. And i want to keep it hidden. I don't want to be able to access it from outside the class...I Don't want main.cpp to have access to this variable

Is there a way to do this?

static int destructorCount;
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Foo.hpp
class Foo
{
private:
    static int destructorCount;
public:
    ~Foo()
    {
        Foo::destructorCount++;
    }
};

Foo.cpp
//Can't initialize static members in the class definition
int Foo::destructorCount = 0;
this doesn't work are you trying to post the code that i didn't? if so thanks
Last edited on
Define 'doesn't work'. Getting compiler errors? What are they. Unexpected output? What were you expecting and what did you get?
I get a match -O linker error whenever i have a static int in private and incrementing it in the destructor
Ahh you are importing the cpp file twice ...never mind i don't like this
I am not importing the .cpp file twice. I'm importing it zero times. I really don't know where you are stuck.
Yeah im retarded you aren't importing :<

I get a match -O linker error...Idk

when i put static int destructorCount; inside the private: area i get the error e
What does your code look like?
Topic archived. No new replies allowed.