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
2009-08-19 06:29:28
+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
2009-08-19 06:29:37
Missing return type. Also the method should be virtual.
Naveen
2009-08-19 06:42:34
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
2009-08-19 09:10:53
+2
A:
It is a keyword introduced as part of the C++/CLI language spefication for the .NET framework.
rahul
2009-08-19 06:29:42
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
2009-08-19 07:03:10
+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
2009-08-19 06:30:18