struct point;
{
int x;
int y;
struct point *p1; //pointer to another structure of the same structure
struct point *p2; //same here
/*personally don't like writing "struct point" coz it seems too long.
so i make an alias with typdef */
}
how would i use the constructor from the struct as a parameter for class constructor. ??
Explain clearer what you want and why would you want it. To clear some things: structs are classes. Only difference between class declared with word class and class declared as struct is default access and inheritance modifiers: for class it is private, for struct: public
i have to design a binary tree structure, for which i was planingen on using struct to indicate each nodes, and a have a class which should be the tree structure itself.
So to instantiate the tree i was thinking of having the contructor for the tree class to take the struct as parameter, and thereby declaring the root as being that struct.
struct nodes{
int value;
nodes* itself;
nodes* right;
nodes* left;
nodes(int a)
{
value = a;
itself = this;
right = NULL;
left = NULL;
};
};
And then within that class have functions for inserting, deletion and so on,
I am not quite sure where you are heading at my constructor for the class look like this
tree::tree(nodes a(int w )){
cout << a.value << a.itself << a.right << a.left << endl;
}
Which doesn't seem to work at the moment.. I don't se why i can't give the parameter like this..
I would like to keep them separated, but the constructor in class has to run the constructor for the struct aswell..
The idea is that the tree constructor has to have the constructor for the struct as parameter, such that, an struct object will be created with the wanted values, and these will be placed as the root for the tree in the tree structure..
tree::tree(int i) : a(new nodes(i))
{
cout << "Value of the tree " << a -> value << endl << "memory location " << a -> itself << endl << "pointer to right struct" << a ->right << endl <<"pointer to left struct "<< a -> left << endl;
nodes *p = a->itself;
cout << "ds" << p -> value << endl; // test if the pointer works
}