Welcome! Log In Create A New Profile

Advanced

[libwiigui] (GuiText array[15]) -> requires arguments

Posted by YoshiParty 
[libwiigui] (GuiText array[15]) -> requires arguments
June 13, 2009 03:35PM
Hi,


I have to declare an array of 15 members of GuiText.
like this:
GuiText myText[15];

but the problem is that GuiText() constructor requires at least one argument( const char *text )

so if it was not an array I just would declare it like
GuiText myText("spaceholder");

But how can I use constructor arguments in case of arrays?

thx for your help
->it is for a new revision of the code manager->so help me:)


EDIT:
Again, vectors saved my life xD



Edited 1 time(s). Last edit at 06/13/2009 03:52PM by YoshiParty.
Re: [libwiigui] (GuiText array[15]) -> requires arguments
June 13, 2009 05:26PM
Can anybody tell me why this doesn't work? Oò

HoldGui();
vector myText(15, "Spaceholder");

mainWindow->Append(&myText.at(0));
ResumeGui();

EDIT:
fixed it through push_back alternative;)



Edited 1 time(s). Last edit at 06/13/2009 05:38PM by YoshiParty.
Re: [libwiigui] (GuiText array[15]) -> requires arguments
June 13, 2009 05:39PM
it's easy, you use the follwing syntax:
obj arr[2]= { obj(1), obj(2) };
Re: [libwiigui] (GuiText array[15]) -> requires arguments
June 13, 2009 05:48PM
Or in C syntax you can use pointers, so: GuiText * myText[15];

and then when you need a new one myText[n] = new GuiText("hello world");
Re: [libwiigui] (GuiText array[15]) -> requires arguments
June 13, 2009 06:00PM
thx for your help

skip my edit above->still crashes....

I'll try your ways :)

EDIT:
yours seem finally working fine :D



Edited 1 time(s). Last edit at 06/13/2009 06:08PM by YoshiParty.
Re: [libwiigui] (GuiText array[15]) -> requires arguments
June 13, 2009 07:15PM
It's good practice to set the ones you're not using null, so myText[n] = NULL;

And just remember to free() one when you're done with it:

if(myText[n] != NULL)
free(myText[n])
Re: [libwiigui] (GuiText array[15]) -> requires arguments
June 14, 2009 11:51AM
Technically, it's ok to free null, there is no need to check for null yourself. The real issue is that it's supposed to be delete and not free when you got the memory with new. It's not allowed to mix them up. At least, the destructor will fail to run, possibly leaking further memory. And at worst, you just freed memory from the wrong heap, causing a crash sometime in the future.
Re: [libwiigui] (GuiText array[15]) -> requires arguments
June 14, 2009 02:01PM
hum, are you sure about that ?
I think it's ok to call free(NULL) because it's handled by gcc but free(pointer) with pointer being unallocated always leaded me to memory crash, I don't think gcc or libs check that for you, at least regarding the "C" free function (Idunno about delete)



Edited 2 time(s). Last edit at 06/14/2009 02:04PM by ekeeke.
Re: [libwiigui] (GuiText array[15]) -> requires arguments
June 14, 2009 07:56PM
You're both right I think. My code was wrong, I meant delete.

So:

if(myText[n])
{
delete(myText[n]);
myText[n] = NULL;
}
Sorry, only registered users may post in this forum.

Click here to login