Segfault when calling a method c++
- by shuttle87
I am fairly new to c++ and I am a bit stumped by this problem. I am trying to assign a variable from a call to a method in another class but it always segfaults. My code compiles with no warnings and I have checked that all variables are correct in gdb but the function call itself seems to cause a segfault. The code I am using is roughly like the following:
class History{
public:
bool test_history();
};
bool History::test_history(){
std::cout<<"test"; //this line never gets executed
//more code goes in here
return true;
}
class Game{
private:
bool some_function();
public:
History game_actions_history;
bool local_variable;
};
bool Game::some_function(){
local_variable = game_actions_history.test_history();
if (local_variable == true){
return true;
}
else{
return false;
}
}
Any tips or advice is greatly appreciated!