473,409 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

pure virtual parameters

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
3 2438
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: santosh | last post by:
Hello, I was going through the Marshal Cline's C++ FAQ-Lite. I have a doubt regarding section 33.10. Here he is declaring a pure virtual destructor in the base class. And again defining...
37
by: WittyGuy | last post by:
Hi, I wonder the necessity of constructor and destructor in a Abstract Class? Is it really needed? ? Wg http://www.gotw.ca/resources/clcm.htm for info about ]
6
by: pakis | last post by:
I am having a problem of pure virtual function call in my project. Can anyone explaine me the causes of pure virtual function calls other than calling a virtual function in base class? Thanks
21
by: sks | last post by:
Hi , could anyone explain me why definition to a pure virtual function is allowed ?
10
by: John Goche | last post by:
Hello, page 202 of Symbian OS Explained by Jo Stichbury states "All virtual functions, public, protected or private, should be exported" then page 203 states "In the rare cases where a...
7
by: sam_cit | last post by:
Hi Everyone, I wanted to know as to what is the exact difference between a virtual function and a pure virtual function? Thanks in advance!!!
3
by: keith | last post by:
Dear mentors and gurus, I noticed at the end of section 22.4 of the 'FAQ-Lite' it says "Note that it is possible to provide a definition for a pure virtual function, but this usually confuses...
2
by: Markus Dehmann | last post by:
I have an abstract base class called Data. It has a pure virtual function virtual void write(std::ostream& out) =0; which writes the internal data to a stream. Now the problem is that this is...
10
by: Rahul | last post by:
Hi, I tried to create a abstract class by having a non-virtual member function as pure, but i got a compilation error saying "only virtual member functions can be pure"... I'm trying to think...
14
by: Jack | last post by:
Hi, I meet a question with it , I did not get clear the different betteen them, for example: #include <iostream>
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.