# Slow Chat Archives > Slow Chat: Visual C++: Yesterday, Today, and Tomorrow >  [RESOLVED] Abstract

## ABuenger

Why does the compiler give me a warning that my class is not abstract if I have a pure virtual function?

But if I declare my class to be abstract without any pure virtual functions I don't get a warning?

That is like a "Are you sure..." prompt to ask the user if he really knowns what he is doing.

Also why have you renamed pure virtual to abstract?

----------


## joncaves

This C++/CLI issue: abstract and pure-virtual are slightly different concepts - if a class has a pure-virtual function then is is abstract - and to make this clear to anyone reading the code it is probaly best if you specify this at the class-head (after all the single pure-virtual function that makes the class abstract may be buried several screens down in the class definition).

But a class can be abstract even if there are no pure-virtual functions - all abstract means is that you have to extend this class if you want to uses - a pure virtual function requires this - but there are other circumstances in which it can arise.

We gave you the ability to use the 'abstract' keyword instead of '= 0' (and the term' pure virtual function') as abstract is the term that is widely used in OOP for this situation while 'pure virtual function' is a C++-ism.

----------


## ABuenger

> if a class has a pure-virtual function then is is abstract - and to make this clear to anyone reading the code it is probaly best if you specify this at the class-head (after all the single pure-virtual function that makes the class abstract may be buried several screens down in the class definition).


If someone tries to instantiate my class or derives a class from it without implementing the pure virtual function the compiler gives him an error. And the compiler should only give him the error but not me any warnings.





> But a class can be abstract even if there are no pure-virtual functions - all abstract means is that you have to extend this class if you want to uses - a pure virtual function requires this - but there are other circumstances in which it can arise.


If I don't want my class to be instanciated I make the constructor protected. So there is absolutely no need for the abstract keyword.





> We gave you the ability to use the 'abstract' keyword instead of '= 0' (and the term' pure virtual function') as abstract is the term that is widely used in OOP for this situation while 'pure virtual function' is a C++-ism.


Google Fight says "pure virtual function" wins over "abstract function" with more than twice as much results ;-)

http://www.googlefight.com/index.php...ct+function%22

----------


## BrandonBray

During the language design process, I did look at existing practices that achieved the same results as 'abstract'. Creating a private virtual destructor is one way to force someone to extend a class. And you've mentioned creating a private constructor.

The problem with all of these solutions is that they require metadata to be created. Solutions in native C++ allow a member function to never be defined as long as it is not called. Metadata does not allow that.

Ultimately, as a language designer, I see actual keywords and language features as a much better solution than work arounds and cool language tricks.

The name 'abstract' comes about because we are targeting the common language runtime. It is the name that is widely used across languages, and has the most cross language understanding. There is no confusion between the difference of an abstract function and a pure virtual function, and as result there is no reason to avoid using the term. Any C++ programmer should know what an abstract function is anyways.

Hope that makes sense,
Brandon Bray
Author of the C++/CLI language

----------

