on the line *binSon[0].add(x);, it give me an error, an expression must have a class type, what do i do?
struct Rectangle
{
tName Name; //name of the rectangle
struct Rectangle *binSon[NDIR_1D]; //left and right son
int Center[NDIR_1D];
int Length[NDIR_1D];
void add(Rectangle x){
if(strcmp(x.Name,Name)<0)
{
if(binSon[0]==NULL)
binSon[0]=&x;
else
*binSon[0].add(x);
}else{
if(binSon[1]==NULL)
binSon[1]=&x;
else
*binSon[1].add(x);
}
}
};
Your problem here really isn’t quite what you think, although it can be solved as is.
The correct syntax is:
The
->operator is member-of-pointer, which handles everything for you. Typically,->should be used with pointers and.with references or the object itself (the exceptions are in interesting spots).To do it how you want (which you really shouldn’t),
(*binSon[0]).add(x)should work. The precedence of the operator is likely your issue at the moment.