Strange error with class members
Hi. I have a very strange problem in my project that is the lost of values in some variables of some classes. I'm using MinGW that comes with CodeBlocks 10.0.5. I didn't post the code, because my code is very large and I believe that my problem can be more comprehensive if I only show code to ilustrate what is happening. In my project, I have a base class that contains many derived classes, like below:
Code:
class Base_Class{
public:
any functions
A a;
B b;
C c...
};
The derived classes have a pointer to base class:
Code:
class A{
public:
any functions
private:
Base_Class* base_class;
other private members
};
Sometimes, a variable of an derived class "loses" your value. Like below:
Code:
class A{
public:
void load_image();
void display_image();
void set_path_image( int new_path_image );
int get_path_image();
private:
Base_Class* base_class;
string path_image;
};
void A::load_image(){
path_image = get_path_from_dialog();
}
void A::display_image(){
show_image( path_image );
}
void A::set_path_image( int new_path_image ){
path_image = new_path_image;
}
int A::get_path_image(){
return path_image;
}
Inside of function load_image, path_image receive the correct value. But, when its exit of function, it loses this value. Then, in function display_image() your value aren't more correct. This happening with variables of other types, like vectors and strings, but not happening with all variables, only with some. My solution is build other class and insert the variable. But this is very awkward and makes the code confusing. This happening in other classes too, but in a lower frequency. Please, help me and sorry for my bad english:redface:.