Leaf_Node bk2;
//......bk2 leaf has an internal node as the parent node
//then i want to reach the sibling leaf node

cout << ((Leaf_Node *)(bk2.parent_node->pointers[1]))->records[0];

//and this line of code gives the error
//i hope this code clearifies the problem

12-04-2002

master5001

I can think of several solutions to your problem. What you are trying to do would be the first thing I would so as it is the easiest.

Example

Code:

int *i = new int;
char j[4] = "hi!!";

i = (int *)j; //casting a char array into an int pointer

//or for an object

struct a {
int i;
};

struct b {
char j[4];
b() {
std::memcpy(j, "hi!!", 4);
}
};

a A;
b *B = (b *)&A;

((a *)b)->i = 6;

Get it? You may also want to make an abstract base class.

12-04-2002

Sang-drax

Re: dereferencing a void *

Quote:

Originally posted by pointing i use a void pointer to point either one of two distinct class types.

Perhaps an abstract base class is a possible solution?

12-05-2002

Codulation

Quoting master5001
>int *i = new int;

Remember to delete...

delete i;

>char j[4] = "hi!!";

Needs to be five elements long for the terminating null

char* j = "hi!!";
char j[] = "hi!!";
char j[5] = "hi!!";

12-05-2002

Polymorphic OOP

Quote:

Originally posted by Codulation char* j = "hi!!";

Just watch out if you do that -- it's not the same as the other two. It creates a pointer to the first element of a string constant in the text area of your program while the other two examples you gave actually make an array with that data. In this case the data isn't being modified, but if you ever want to change the value of a letter then you'd most-likely get an error because you'd be trying to access a section of the programs memory that should not be being altered at runtime!

12-06-2002

Codulation

Thanks for clarifying that PolyOOP, That syntax can be used like a char array, but attempted modifications will have undefined results (most likely a seg fault).