neted class & virtual function

F

fintrack

HI,

how do i overide a virtual function in a innerclass. the scenario is
like

class A
{
public:
class B
{
public:
virtual void go(void);
void f(void);
};
}

class A::B::go(void)
{
f();
}

I want to write a class C derived from class A and override the
function go() is it possible?

TIA,
fin.
 
C

Carlos Martinez

HI,

how do i overide a virtual function in a innerclass. the scenario is
like

class A
{
public:
class B
{
public:
virtual void go(void);
void f(void);
};
}

class A::B::go(void)
Error.
void A::B::go(void)
{
f();
}

I want to write a class C derived from class A and override the
function go() is it possible?

I think, it's possible.
 
B

Bart

how do i overide a virtual function in a innerclass. the scenario is
like

class A
{
public:
class B
{
public:
virtual void go(void);
void f(void);
};
}

class A::B::go(void)
{
f();
}

I want to write a class C derived from class A and override the
function go() is it possible?

Yes, but you have to explicitly derive C::B from A::B like so:

class C : public A
{
public:
class B : public A::B
{
public: virtual void go(void);
};
};

If you tell us what you're trying to do maybe we can suggest something
else, like a template for example.

Regards,
Bart.
 
F

fintrack

Hi Bart,

I have a library which has class A in it as above.

I want to change the method go() in it to something else than done in
base class.

i cant change the base class.

if i derive it the way you said how do i call it in my main program??


thanks,
fin
 
B

Bart

I have a library which has class A in it as above.

I want to change the method go() in it to something else than done in
base class.

i cant change the base class.

if i derive it the way you said how do i call it in my main program??

As with any other class. You create an instance of the derived class
whenever an instance of the base class could be used. If this class is
called back by the A class then you probably need to pass an object as
a parameter or something of that sort. I can't really say just by
looking at your short example.

Regards,
Bart.
 

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,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top