C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

pure virtual

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
vasanth kumar
Guest





PostPosted: Wed Sep 29, 2004 8:48 am    Post subject: pure virtual Reply with quote



I am writing a small example below. I want to know, is this allowed as per
the standard C++. We make an abstract class by making any membor method as
pure virtual. when we make it pure virtual, what is the meaning of providing
definition as shown below. are the code lines in bold are good practice.

class Vehicle {
public:
virtual void startEngine() = 0;
virtual ~Vehicle() {};
};
void Vehicle::startEngine()
{
}
class Car : public Vehicle {
public:
void startEngine(){
Vehicle::startEngine();
}
};

void main()
{
Car objCar=new Car();
objCar.Vehicle::startEngine();
}

Thanks,
Vasanth


Back to top
Sharad Kala
Guest





PostPosted: Wed Sep 29, 2004 9:06 am    Post subject: Re: pure virtual Reply with quote




"vasanth kumar" <vasanth.kumar (AT) eds (DOT) com> wrote in message

Quote:
I am writing a small example below. I want to know, is this allowed as per
the standard C++. We make an abstract class by making any membor method as
pure virtual. when we make it pure virtual, what is the meaning of
providing
definition as shown below. are the code lines in bold are good practice.

Providing definition for pure virtual functions is legal. It's not a
question of good/bad practice but more to do with your requirements.
Consider this code -
struct base
{
// ...
virtual ~base() = 0; //Definition required
};

struct derived : base
{

};

int main()
{
derived d;
}; // Linker error



Quote:
void main()

Always, int main ()

Sharad



Back to top
vasanth kumar
Guest





PostPosted: Wed Sep 29, 2004 9:29 am    Post subject: Re: pure virtual Reply with quote



thanks for the reply.

yes, destructor case I understand. provides default destructor. can anyone
think of a requirement for providing this definition for other member
functions.

-Vasanth
-------------
"Sharad Kala" <no_spam.sharadk_ind (AT) yahoo (DOT) com> wrote

Quote:

"vasanth kumar" <vasanth.kumar (AT) eds (DOT) com> wrote in message

I am writing a small example below. I want to know, is this allowed as
per
the standard C++. We make an abstract class by making any membor method
as
pure virtual. when we make it pure virtual, what is the meaning of
providing
definition as shown below. are the code lines in bold are good practice.

Providing definition for pure virtual functions is legal. It's not a
question of good/bad practice but more to do with your requirements.
Consider this code -
struct base
{
// ...
virtual ~base() = 0; //Definition required
};

struct derived : base
{

};

int main()
{
derived d;
}; // Linker error



void main()

Always, int main ()

Sharad





Back to top
Sharad Kala
Guest





PostPosted: Wed Sep 29, 2004 9:34 am    Post subject: Re: pure virtual Reply with quote


"vasanth kumar" <vasanth.kumar (AT) eds (DOT) com> wrote in message
Quote:
thanks for the reply.

You are welcome, please don't top-post.

Quote:
yes, destructor case I understand. provides default destructor. can anyone
think of a requirement for providing this definition for other member
functions.

Sure, Herb Sutter gives 3 cases in which pure virtual functions could have a
body - http://www.gotw.ca/gotw/031.htm. He also says that the destructor
example is the most common.

Sharad



Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.