pure virtual class

P

Prawit Chaivong

Hi, gurus

The Ctor & Dtor of pure virtual class (interface class) should be

IMyClass() = 0;
or
IMyClass() { }

Thank in advance

Prawit C.
 
V

Victor Bazarov

Prawit said:
The Ctor & Dtor of pure virtual class (interface class) should be

IMyClass() = 0;
or
IMyClass() { }

First of all, there is no such thing as "pure virtual class". There is
an 'abstract class', maybe you meant to use that term? I'll assume so.
To answer what I think was your question, (a) you cannot make a c-tor
pure by adding "=0" to it because c-tors cannot be virtual and only the
virtual members can be declared pure, and (b) as to the d-tor, it's up
to you, but remember that even if you do declare the d-tor pure, you still
need to provide an [empty] implementation, since it's definitely going to
be called.

V
 
B

BigBrian

Hi, gurus
The Ctor & Dtor of pure virtual class (interface class) should be

IMyClass() = 0;
or
IMyClass() { }

Thank in advance

Prawit C.

Homework?

You could at least search the newsgroup to determine the answer for
yourself. Also, maybe you should read your text book.
 
P

Peter Julian

Prawit Chaivong said:
Hi, gurus

The Ctor & Dtor of pure virtual class (interface class) should be

IMyClass() = 0;
or
IMyClass() { }

Thank in advance

Prawit C.

An abstract class's ctor and dtor can't be pure-virtual. The logic is
simple: a derived class can't overide / overload base class ctor(s) or
d~tor. This is true whether the base is abstract or not.

Now you know why you can't "call", but only "invoke", a base ctor or d~tor.
 
V

Victor Bazarov

Peter said:
An abstract class's ctor and dtor can't be pure-virtual. The logic is
simple: a derived class can't overide / overload base class ctor(s) or
d~tor. This is true whether the base is abstract or not.

Now you know why you can't "call", but only "invoke", a base ctor or d~tor.

I can call the d-tor without any problem. I can even call it for
an int or a double. Didn't you know?

V
 

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

Staff online

Members online

Forum statistics

Threads
474,296
Messages
2,571,535
Members
48,279
Latest member
RedaBruno6

Latest Threads

Top