cplusplus.com
C++ : Forum : General C++ Programming : rules of inheritance when passinf by ref
 
cplusplus.com
Information
Documentation
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs


post rules of inheritance when passinf by reference

kenr (7)

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


helios (9402)
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?
kenr (7)
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.
Abramus (170)
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.