rules of inheritance when passinf by reference


void SomeFunc(ClassA **inst)
{
...
}

Class ClassA
{
...
}

Class ClassB: public ClassA
{
...
}

main
{

ClassA *instA = new ClassB();
SomeFunc(&instA); // this compiles and works fine

ClassB *instB = new ClassB();
SomeFunc(&instB); // but this will not compile
}

I tried a static cast but still could not get to compile



here is what the complier is grippin about:
cannot convert `ClassB*' to `ClassA**' for argument


SomeFunc((ClassA **)&instB); should work.

Why do you need to pass a pointer to a pointer? Are you going to modify where the pointer points to?
Are you going to modify where the pointer points to?

No. This was more of an exercise in pointer/address gymnastics which I need lots of practice in.
Implict conversion from ClassB** to ClassA** is inhibited because it is dangerous. Please read this:

http://www.parashift.com/c++-faq-lite/proper-inheritance.html#faq-21.2
Topic archived. No new replies allowed.