On 2007-09-19 13:22, Jonas Huckestein wrote:
> Hi there,
>
> I was wondering, whether I
> can access members of a
> derived class from within
> it, if I accessed it from a
> virtual function on the base
> classpointer ^^ Example:
>
> class A {
> virtual void oskar(void);
> };
>
> class B : A {
> void emil(){};
> void oskar(void)
> {emil();};};
>
> A* peter = new B;
> B->oskar();
>
> Is this allowed? I know it
> is not possible to call emil
> directly, but thiswould be a
> fine workaround.
As D. Susman pointed out, this does not look like what you asked for,
perhaps you meant something like this:
class A {
virtual void foo();
};
class B : public A {
void foo() { bar(); }; // Call B::bar() in B::foo()
void bar();
};
int main() {
A* a = new B;
a->foo(); // This will call B::bar();
}
--
Erik Wikström