By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,911 Members | 1,171 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,911 IT Pros & Developers. It's quick & easy.

pure virtual parameters

P: n/a
I have a doubt. Given a function like this:

class bar {
public:
virtual void foo(int i = 0) = 0;
};

when implementing this virtual function, will the above enforce the default
parameter in all implementations?

class der : public bar
{
void foo(int i) {}
};

or should I again specify "int i = 0"?

Thanks.
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Alex wrote:
I have a doubt. Given a function like this:

class bar {
public:
virtual void foo(int i = 0) = 0;
};

when implementing this virtual function, will the above enforce the
default parameter in all implementations?

class der : public bar
{
void foo(int i) {}
};

or should I again specify "int i = 0"?

Thanks.


I took your code pasted it in to a test project
and calling der.foo() will produce a error on GCC 3.2.
Then added void foo( int i = 0 ) and calling der.foo()
does not produce a error. So I guess that it does not
get the default parameter.
--
Thank You
Bo Hunter
Registered Linux User #393766 http://counter.li.org/
Jul 23 '05 #2

P: n/a
"Alex" <no@domain.com> wrote in
news:db**********@nsnmpen2-gest.nuria.telefonica-data.net:
I have a doubt. Given a function like this:

class bar {
public:
virtual void foo(int i = 0) = 0;
};

when implementing this virtual function, will the above enforce the
default parameter in all implementations?
Nope. (At least not where foo() is called through a pointer/reference to a
more-derived type....)
class der : public bar
{
void foo(int i) {}
};

or should I again specify "int i = 0"?


You again specify "int i = 0".
Jul 23 '05 #3

P: n/a
Alex wrote:
I have a doubt. Given a function like this:

class bar {
public:
virtual void foo(int i = 0) = 0;
};

when implementing this virtual function, will the above enforce the default parameter in all implementations?

class der : public bar
{
void foo(int i) {}
};

or should I again specify "int i = 0"?


Specify again (or pick another method to default the parameter).

Default parameters resolve at compile time, so they resolve based on their
object's static type. Virtual methods resolve at runtime.

--
Phlip
http://www.c2.com/cgi/wiki?ZeekLand
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.