I made a program that follows the same logic that my project. However, the code not compiled. After the error, I compared the two programs to see if the simple program have the same logic that the my project have. I didn't see any difference. The code is below:
main.cpp:
Code:
#include <class_a.h>
#include <iostream>
#include <deque>
using namespace std;
std::deque<A*> tests_objects;
int main()
{
tests_objects.push_back( &A() );
( *( tests_objects.begin() ) )->b.set_test_variable_2( 2 );
( *( tests_objects.begin() ) )->b.get_test_variable().push_back( 5 );
return 0;
}
class_a.cpp:
Code:
#include <class_a.h>
//Description:This file contain the implementation of class A.
//Name of class:A
//Way to use:Declare a instance of this class in beginning of app, in main.cpp.
A::A(){
initialize_class_composed();
}
//Name of funcion:void A::initialize_class_composed()
//Description:Initialize classes members of this class.
//Way to use:This function might be called in constructor of this class.
//Observations:None.
void A::initialize_class_composed(){
b.set_a( this );
}
class_a.h:
Code:
#ifndef CLASS_A_H_INCLUDED
#define CLASS_A_H_INCLUDED
#include <class_b.h>
class A{
public:
A();
void initialize_class_composed();
B b;
};
#endif // CLASS_A_H_INCLUDED
class_b.cpp:
Code:
#include <class_b.h>
//Description:This file contain the implementation of class B.
//Name of class:B
//Way to use:Declare a instance in class A.
B::B(){
}
std::deque<int>& B::get_test_variable(){
return test_variable;
}
std::deque<int>::iterator& B::get_iterator_test_variable(){
return iterator_test_variable;
}
void B::set_test_variable_2( int new_test_variable_2 ){
test_variable_2 = new_test_variable_2;
}
int B::get_test_variable_2(){
return test_variable_2;
}
void B::set_a( A* new_a ){
a = new_a;
}
A* B::get_a(){
return a;
}
class_b.h:
Code:
#ifndef CLASS_B_H_INCLUDED
#define CLASS_B_H_INCLUDED
#include <deque>
class A;
class B{
public:
B();
std::deque<int>& get_test_variable();
std::deque<int>::iterator& get_iterator_test_variable();
void set_test_variable_2( int new_test_variable_2 );
int get_test_variable_2();
void set_a( A* new_a );
A* get_a();
private:
A* a;
std::deque<int> test_variable;
std::deque<int>::iterator iterator_test_variable;
int test_variable_2;
};
#endif // CLASS_B_H_INCLUDED
All this is very strange. What I did in this program I did in my project several times without any crash occurred. What happened is that sometimes the data value was lost. But this didn't happen with all the data, only a few. This is even more curious. How can there be many of the same data type that will work and others that not work in the same class? If it is a error, should not be equal for all data? I don't understand.