I have to use c++98 for application i am developing for,
[EDIT2]
i want to control the behavior of constructor based on a static member of class, (in my case a boolean)
i want to control the behavior of constructor based on if it is a first ever call to constructor or not.
For first ever constructor call, i want to execute some extra code but it must not execute in consecutive calls,
For this i decided to have a static bool that will have default value of false, and after first constructor call, it will be set true for every other call.
class data_sender {
private:
static bool library_initialized;
public: // etc.
};
This is kept private because i dont want consumer of this class to manipulate this directly.
Its not const because obviously i want to change it inside constructor.
Now i cannot assign the default value for this, it says c++ forbids this non-const static variable initialization.
I think my approach is wrong here and i should be using some other method.
I am relatively new to c++ so even if you point me to some article or tell me what to search for this.
[EDIT]
Another strange thing i noticed is, when i define the library_initialized as false within the .h file,
class data_sender { .... };
bool data_sender::library_initialized = false;
it gives me linker error.
But if i define it inside the data_sender.cpp, it allows me to do this,
bool data_sender::library_initialized = false; // This is inside data_sender.cpp
You should be doing this as
data_sender::library_initialized = false;
actually, afaik
Diego
Chandresh
Harshal
klimi
Junaid
MRT