Topic: A question !!
Author: konfjo@eua.ericsson.se (Fredrik Jonsson)
Date: 11 Jul 1994 10:06:32 GMT Raw View
In article 23110@usb.ve, 91-23348@shaddam.usb.ve (Hector Luis Palacios Verdes) writes:
>Hi,
>Mi problem is (in Borland C++ 3.1):
>
>how do you do it to send b () to c1??
>
>((ACCOUNT_with_interes *) c2)->b ();
>// ????
>
>c2 = (ACCOUNT_with_interes *) c1;
>c1->b ();
>// ????
>
>answerme please!!!!
>
You cant! The reason is that the member function b() is not declared in
the baseclass ACCOUNT. What you'll have to do is to add the virtual members
to the baseclass. Here's a brief example:
class ACCOUNT {
public:
.
.
virtual void b() { } // do nothing or declare it pure virtual with "= 0";
virtual void c() { } // - " -
virtual void d() { } // - " -
};
you then overload them with
class ACCOUNT_with_interes : public ACCOUNT
{
public:
.
.
virtual void b() { ... ACCOUNT_with_interes specific overloaded code }
};
You will now get the expected result when you call c1->b().
__________
F. Jonsson
Author: 91-23348@shaddam.usb.ve (Hector Luis Palacios Verdes)
Date: Fri, 8 Jul 1994 22:34:16 GMT Raw View
Hi,
Mi problem is (in Borland C++ 3.1):
class ACCOUNT {
public:
a ();
~~
~~
}
class ACCOUNT_with_interes : public virtual ACCOUNT {
public:
b ();
~~~
~~~
~~~
}
class ACCOUNT_with_check : public virtual ACCOUNT {
public:
c ();
~~
~~
~~
}
class ACCOUNT_both : public ACCOUNT_with_interes,
public ACCOUNT_with_check {
public:
d ();
~~
~~
~~
}
ACCOUNT *c1 = new ACCOUNT_with_interes (~~~);
ACCOUNT_with_interes c2;
how do you do it to send b () to c1??
((ACCOUNT_with_interes *) c2)->b ();
// ????
c2 = (ACCOUNT_with_interes *) c1;
c1->b ();
// ????
answerme please!!!!
--
Sorry, Hector Luis Palacios Verdes
my english is BAD El Barlovente~o
i'm venezuelan!!!
91-23348@usb.ve