Are pointers to pointers legal in c++? I’ve come across this SO question: Pointer to Pointer to Pointer
But the answers aren’t clear if it is legal c++ or not. Let’s say I have:
class A{
public:
void foo(){
/* ect */
}
};
class B{
public:
A* a;
/* ect */
};
void Some_Func() {
B *b;
// besides this looking ugly, is it legal c++?
b->a->foo();
};
Is the line b->a->foo() OK to write? Is there a better way to represent this expression?
This is perfectly valid.But the term you are using “pointer to pointer” is wrong.
the term means a double pointer like
**P,a pointer which holds the address of another pointer.but your case is the pointer(of class A) is an member of a class whose pointer(of class B) is created by you in
some_func