Defining chatbox via a class

Started by starkhorn, 01 September 2015, 01:06:35


Ok, I feel a bit silly here but I'm confused and I'm looking for a bit of help.

So I have a class where one of the data items is a chatbox

class Test

sf::RenderWindow gameWindow;
tgui::Gui gui;
tgui::ChatBox::Ptr chatbox;

Now in the class constructor, I want to set the chatbox container so that it is in the gui, i.e. like below.

tgui::ChatBox::Ptr chatbox(gui);

Now obviously if I do this in the class definition, it does not compile. So I'm assuming there is a method that I call call in the Test class constructor but I cannot for the life figure out which method to call.


You have to do such things in the constructor initializer list:
Code (cpp) Select
Test::Test() :

Of course that means that the window and gui would also have to be put in the initializer list because otherwise the gui may not yet be fully initialized when creating the chatbox.

But alternatively you can just not initialize it in which case it will just be a nullptr and then in your constructor you just add:
Code (cpp) Select
chatbox = tgui::ChatBox::Ptr(gui);