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.
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.