tags:

views:

482

answers:

5

Can we write abstract keyword in C++ class?

+12  A: 

No, C++ has no keyword abstract. However, you can write pure virtual functions; that's the C++ way of expressing abstract classes.

Martin v. Löwis
+12  A: 

No.

Pure virtual functions, in C++, are declared as:

class X
{
    public:
        virtual void foo() = 0;
};

Any class having at least one of them is considered abstract.

DevSolar
Missing return type. Also the method should be virtual.
Naveen
Absolutely correct, thank you. Man, I have to get my head out of code maintenance and into writing new code once in a while - it dissolves your brain only looking at other people's errors. :-D
DevSolar
+2  A: 

It is a keyword introduced as part of the C++/CLI language spefication for the .NET framework.

rahul
...which isn't C++. Seriously, ref, that's encroachment...
DevSolar
Technically, it's a Microsoft C++ extension for native code even if you don't target .NET, so it's not C++/CLI specific. Just an extension, same as `__interface` or `__declspec(property)`. Still not ISO C++ of course.
Pavel Minaev
+3  A: 

no, you need to have at least one pure virtual function in a class to be abstract.

Here is a good reference cplusplus.com

Svetlozar Angelov
+3  A: 
#define abstract
Ken
I love you. 10char
Legatou