cast

L

Lenin

Hi,
I have a multiply inherited class "C" as folloows. None of
them are inherited as virtual base class except that they have virtual
functions.

class b1
{
....
virtual void f1() {}
}

class b2
{
....
virtual void f2() {}
}

class c: pulbic b1, public b2
{
.....
}

Now that, I have a function fun() which takes b1's pointer and now
I want to call b2's functions from there. Assume that the function
is called with argument as address of c's object like below.

void fun(b1 *bp1)
{
b2 *bp2 = (b2*) (c*) bp1;
bp2->f2();
}


somewhere I call like this

c obj;
fun(&obj);

This works fine. But in this case, do I need to use dynamic cast
inside the function fun? Assume that the runtime error check for junk
pointer is not needed in my case.

Thanks in advance.
 
L

Lenin

Lets say the function fun and the b1,b2 class are part of some library
and fun is a callback. Then in that case, will the c style casting
works irrespective of the compiler/platform?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top