IGUIElement collection
IGUIElement collection
I have an std::map that contains IGUIElements. I use this to track all my GUI elements. Lets say I add an IGUIEditBox to this map. When I try this:
controlList[id].setMultiLine(true);
This will not work because IGUIElement does not have this function. So I try to cast it as IGUIEditBox:
(gui::IGUIEditBox)controlList[id].setMultiLine(true);
And it says you can not cast with an abstract class. Can I not have edit boxes in an std collection class like this? Any ideas would be appreciated.
controlList[id].setMultiLine(true);
This will not work because IGUIElement does not have this function. So I try to cast it as IGUIEditBox:
(gui::IGUIEditBox)controlList[id].setMultiLine(true);
And it says you can not cast with an abstract class. Can I not have edit boxes in an std collection class like this? Any ideas would be appreciated.
Re: IGUIElement collection
Save the element in a variable:barakatx2 wrote:I have an std::map that contains IGUIElements. I use this to track all my GUI elements. Lets say I add an IGUIEditBox to this map. When I try this:
controlList[id].setMultiLine(true);
This will not work because IGUIElement does not have this function. So I try to cast it as IGUIEditBox:
(gui::IGUIEditBox)controlList[id].setMultiLine(true);
And it says you can not cast with an abstract class. Can I not have edit boxes in an std collection class like this? Any ideas would be appreciated.
Code: Select all
irr::gui::IGUIEditBox*EditBox=dynamic_cast<irr::gui::IGUIEditBox*>(controlList[id]);
EditBox->setMultiLine(true);
Re: IGUIElement collection
the "casting-braces" are wrong !!!barakatx2 wrote:(gui::IGUIEditBox)controlList[id].setMultiLine(true);
you're now casting the return value of setMultiLine(true) (which has no return value) !!!
try this:
Code: Select all
((gui::IGUIEditBox)controlList[id]).setMultiLine(true)
should it not be:
Code: Select all
((gui::IGUIEditBox)controlList[id])->setMultiLine(true)
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Re: IGUIElement collection
This isn't right, you should cast to a pointer to a IGUIEditBox, not to a IGUIEditBox object ...Acki wrote:also are you sure to use the dot operator ???
should it not be:Code: Select all
((gui::IGUIEditBox)controlList[id])->setMultiLine(true)
@barakatx2:
Here some advices:
1. Don't save Irrlicht objects in a container, save them as pointers to Irrlicht objects.
Code: Select all
#include <vector>
std::vector<IGUIElement*> GUIVector;
2. If you wanna cast a basic type to a diverted type (hope the idiom is correct), use a dynamic_cast.
Code: Select all
#include <vector>
class Base{};
class Diverted:Base
{
public:
void SomeFunctionBaseDoesNotHave(){}
};
std::vector<Base*> BaseVector;
Base*PointerToBase=new Diverted();
//PointerToBase->SomeFunctionBaseDoesNotHave(); //The object itself is diverted, but the pointer is not, so you can't call the function.
BaseList.push_back(PointerToBase); //Now how to get SomeFunctionBaseDoesNotHave?
Diverted*PointerToDiverted=dynamic_cast<Diverted*>(BaseList.at(0)); //Get first item of the vector, cast it to diverted type and save it.
PointerToDiverted->SomeFunctionBaseDoesNotHave(); //OK.
Code: Select all
//Imagine that the used constructors exist.
IGUIEditBox Object;
IGUIEditBox*Pointer=new IGUIEditBox();
Object.getText();//OK.
Pointer->getText();//Also OK.
Object->getText();Error, Object is not able to be casted into adress.
Pointer.getText();Error, the adress is just a number, no IGUIEditBox object.
Please do not use dynamic_cast. Irrlicht is compiled without rtti, so that won't work. Use c-casts or static_cast instead.
And your main problem is that you try to cast objects instead of casting pointers. Work with pointers instead.
And your main problem is that you try to cast objects instead of casting pointers. Work with pointers instead.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: IGUIElement collection
This was right. Also I am using pointers, I had just put a period incorrectly in the code I pasted for some reason @_@. But ((gui::IGUIEditbox*)controlList[id])->setMultiLine(true); works. Thank you!Acki wrote:the "casting-braces" are wrong !!!barakatx2 wrote:(gui::IGUIEditBox)controlList[id].setMultiLine(true);
you're now casting the return value of setMultiLine(true) (which has no return value) !!!
try this:also are you sure to use the dot operator ???Code: Select all
((gui::IGUIEditBox)controlList[id]).setMultiLine(true)
should it not be:Code: Select all
((gui::IGUIEditBox)controlList[id])->setMultiLine(true)
Re: IGUIElement collection
yeah, sorry, just a typo, I forgot the asterisk...TomTim wrote:This isn't right, you should cast to a pointer to a IGUIEditBox, not to a IGUIEditBox object ...Acki wrote:also are you sure to use the dot operator ???
should it not be:Code: Select all
((gui::IGUIEditBox)controlList[id])->setMultiLine(true)
as barakatx2 already figured out it must be:
Code: Select all
((gui::IGUIEditbox*)controlList[id])->setMultiLine(true);
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java