Hi guys
I'm having a little problem in my code, but I don't know how to solve it.
I have a class called Myclass. This class have a public var, called Tag, where I save a int number.
1 2 3 4 5 6 7
|
class Myclass
{
public:
int Tag;
Myclass();
};
|
Now, in the main function, I creates an array of Myclass, so
|
Myclass** classes = (Myclass**)malloc(sizeof(Myclass)*100);
|
later, I assigns a value to each Tag, belonging to each array element
1 2 3 4 5 6 7 8 9 10 11 12
|
int main()
{
Myclass** classes = (Myclass**)malloc(sizeof(Myclass)*100);
for (int i=0; i < 100; i++)
{
classes[i] = new Myclass();
classes[i]->Tag = i;
}
printf ("The value of net[5]->Tag = %d\n", (*((Myclass*)classes+5)).Tag);
}
|
but when I want to print the value of classes[5]->Tag, im getting the address of the value, but no the int number of Tag.
I know that I can use an indexer (like, classes[5]->Tag), but I need to access the element in the shown way.
Somebody can tell me how can I fix this problem.
Thanks in advance