static vectors/maps

Hello all

Could anyone please tell me how do I declare and make use of static vectors & static maps?

I have one base class and 3 classes derived from it. I want the vector populated in one class to be available to the other classes. The only solution I see to it is to make that vector/map static but I dont know how to do it correctly.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//=========== BASE CLASS ===========
// base.h file
class base
{
        struct someStruct
	{
	
	};
	
	static vector<someStruct> vec;
};

// base.cpp file
base::base ()
{

}
base::~base ()
{
	
}

could anyone please tell me how do I use this static vector in the derived classes?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//=========== DERIVED CLASS_1 POPULATES THE 'BASE CLASS STATIC VECTOR' ===========
// classDerv1.h
class classDerv1 : public base
{
	void populateVect();
};

// classDerv1.cpp
classDerv1::classDerv1 ()
{
	
}
classDerv1::~classDerv1 ()
{
	
}
void classDerv1::populateVect()
{
	// populate the static vector inherited from base class
}

//=========== DERIVE CLASS-2 'MAKES USE OF THE 'BASE CLASS STATIC VECTOR' POPULATED IN 'DERIVED CLASS_1' ==========='
// classDerv2.h
class classDerv2 : public base
{
	void dosomethingtoStaticVect();
};
void classDerv2::dosomethingtoStaticVect()
{
	// do something to the static vector inherited from base class and populated in class classDerv1
}

Thanks
Last edited on
You need to make the static object either protected or public. Your code shown here has it private.
Topic archived. No new replies allowed.