Defining chatbox via a class
« on: 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

Code: [Select]

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.

Code: [Select]
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.



  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: Defining chatbox via a class
« Reply #1 on: 01 September 2015, 01:09:36 »
You have to do such things in the constructor initializer list:
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:
chatbox = tgui::ChatBox::Ptr(gui);