Overloading in subclass

J

Joseph Turian

Let's say I have the following:

class Foo {
public:
void func();
};

class Bar : public Foo {
public:
void func() {
// do some work...

this->Foo::func();
}
}

Now, if I have an object b of type Bar, and I call b.func(), it will
call b.Bar::func(), which in turn will call b.Foo::func(), correct?


Joseph
 
R

Rob Williscroft

Joseph Turian wrote in @z14g2000cwz.googlegroups.com in comp.lang.c++:
Let's say I have the following:

class Foo {
public:
void func();
};

class Bar : public Foo {
public:
void func() {
// do some work...

this->Foo::func();
}
}

Now, if I have an object b of type Bar, and I call b.func(), it will
call b.Bar::func(), which in turn will call b.Foo::func(), correct?

Correct.


Rob.
 
R

Rolf Magnus

Joseph said:
Let's say I have the following:

class Foo {
public:
void func();
};

class Bar : public Foo {
public:
void func() {
// do some work...

this->Foo::func();
}
}

Now, if I have an object b of type Bar, and I call b.func(), it will
call b.Bar::func(), which in turn will call b.Foo::func(), correct?

Right.
 
D

David White

Joseph Turian said:
Let's say I have the following:

class Foo {
public:
void func();
};

class Bar : public Foo {
public:
void func() {
// do some work...

this->Foo::func();

You can just write Foo::func(); here.
}
}

Now, if I have an object b of type Bar, and I call b.func(), it will
call b.Bar::func(), which in turn will call b.Foo::func(), correct?

Yes. You aren't really "overloading" here, since the compiler is not
choosing which of several functions to call based on their argument lists.

DW
 

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
474,298
Messages
2,571,542
Members
48,283
Latest member
RitaVui655

Latest Threads

Top