First question on StackOverflow. And I want apologize for my bad English.
I'm actually developing a menu for a video game. I want clear the code, so I want use vector to call different functions (like charge a picture or modify the text)
here's the code :
Menu.hh :
class Menu
{
int _position
std::vector<Menu> _graph;
std::list<sf::Text> _text;
public:
//constructors and destructors
virtual std::list<sf::Text> &modifyText();
}
Menu.cpp
std::list<sf::Text> &modifyText()
{
std::cout << this->_position << std::endl;
this->_text = this->_graph[this->_position].modifyText();
return (this->_text); // don't care of the return
}
void Menu::initGame()
{
this->_graph.push_back(MenuBase());
// if i Put this code on the constructor, the constructor call himself and not the MenuBase constructor
this->modifyText();
}
MenuBase.hpp
class MenuBase : public Menu
{
//constructor and destructor
std::list<sf::Text &modifyText(){std::cout << "work" << std::endl;
//I've more code, but it's just initialization of text and the return.
//The work is here to show what's happen on the standard output.
}
The ouptut of this code is : 0, 0 then SegFault. I expect to see "0" then "work" on standard output. So, why the MenuBase function is not called ?
To have the full code, here's the gitHub repository : https://github.com/Aridjar/AW_like