ERROR, with my code.

Posts 1–12 of 12 · Page 1 of 1
ERROR, with my code.
When i use AddItem[Located in sTab struct. I get an error about Char*Item_Name. It Compiles fine just when I call that one function everything got a problem.



[php]struct sItem
{
char* Name, **Options;
int* Value;
bool Selectable;
sItem(char* NAME, char** OPTIONS, int* VALUE, bool SELECTABLE)
{
Name=NAME;Options=OPTIONS;Value=VALUE;Selectable=S ELECTABLE;
}
~sItem()
{}
};

struct sTab
{
int noItems, totHeight;
char* Name;
sItem* Items;
int Selected;

void AddItem(char* Item_Name, char** Options, int* DefaultValue=0)
{
Items[noItems]=sItem(Item_Name, Options, DefaultValue, true);
noItems++;
totHeight=(noItems*15);
}
void AddText(char* Item_Name, char* Option)
{
Items[noItems]=sItem(Item_Name, (char**)Option, 0, false);
noItems++;
totHeight=(noItems*15);
}

sTab(){
Name="New Tab";
noItems=0;
totHeight=60;
Selected=0;
}
~sTab()
{
Items=new sItem((char*)NULL,(char**)NULL, (int*)NULL, (bool)NULL);
Name=(char*)NULL;
noItems=0;
totHeight=0;
}
};
[/php]
Pic of the Error?
extactly, whats the error you get?
Image added
Code:
sItem* Items; 
Items=new sItem((char*)NULL,(char**)NULL, (int*)NULL, (bool)NULL); 
Items[noItems]=sItem(Item_Name, Options, DefaultValue, true);
i only see you creating 1 item

be very careful with pointers!

Code:
char* Name, **Options;
int* Value;
very dangerous thing if you do it the wrong way
Quote Originally Posted by Gordon` View Post
Code:
sItem* Items; 
Items=new sItem((char*)NULL,(char**)NULL, (int*)NULL, (bool)NULL); 
Items[noItems]=sItem(Item_Name, Options, DefaultValue, true);
i only see you creating 1 item

be very careful with pointers!

Code:
char* Name, **Options;
int* Value;
very dangerous thing if you do it the wrong way
I am still lost
Honey its cuz when you add a new item. That item doesn't exist.

Right there babay
Code:
Items[noItems]=sItem(Item_Name, (char**)Option, 0, false);
You either need to either initialize an array of sItems
Code:
Items = new sItems[some number];
or
make Items a sItems**, meaning it will only point to new sItems, and not hold the struct in the array honey.

I would do the first since if you do the latter its a good chance your structs will be deleted since they are declared in scope babe.
Quote Originally Posted by why06 View Post
Honey its cuz when you add a new item. That item doesn't exist.

Right there babay
Code:
Items[noItems]=sItem(Item_Name, (char**)Option, 0, false);
You either need to either initialize an array of sItems
Code:
Items = new sItems[some number];
or
make Items a sItems**, meaning it will only point to new sItems, and not hold the struct in the array honey.

I would do the first since if you do the latter its a good chance your structs will be deleted since they are declared in scope babe.
I am trying both now
btw that made more sense when I was a girl.
now i am getting a similar problem with my drawtext Then when i dont drawText I get an error with Show() Function
Quote Originally Posted by topblast View Post
now i am getting a similar problem with my drawtext Then when i dont drawText I get an error with Show() Function
Check over any code that uses pointers, Access Violations are related to reading memory (usually from bad pointers).

It might be that you're doing the same as before, trying to access a pointer as an array to something when you've only initialised it as a single item.
Posts 1–12 of 12 · Page 1 of 1

Post a Reply

Tags for this Thread

None

Talk with us