Calling static methods at the beg. of the program

N

nafai3000

Hello I want to do sth like this, but I don't know exactly how:

// c.h
class C {
....
static int var1[];
static map<X,Y> var2;
static void initVar2();
};

// c.cpp

int C::var1 = {1,2,3,4,5}; // Easy to init. as a constant.

C::initVar2(); // To init. var2 I need to call a method!

....

// end c.cpp
 
C

CrayzeeWulf

nafai3000 said:
// c.h
class C {
...
static int var1[];
static map<X,Y> var2;
static void initVar2();
};

One possible solution:

class StaticInitializer
{
public:
StaticInitializer()
{
// Initialize C::var1, C::var2, etc.
}
} ;

// c.h
class C {
....
static int var1[];
static map<X,Y> var2;
static const StaticInitializer mStaticInitializer ;
};
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,831
Latest member
HealthSmartketoReviews

Latest Threads

Top