Is this a pure abstract class?
class C
{
public:
static const std::string S;
C() {}
virtual ~C() {}
virtual void v() = 0;
}
I believe it is not, following this definition from WikiBooks:
A pure Abstract class has only abstract member functions and no data or concrete member functions.
It can't be pure abstract because it does not have only abstract member functions:
Now my teachers claim it is a pure abstract class, because:
Constants included in a pure virtual class are not considered attributes. They are immutable elements of a class and therefore they don't violate its abstractness. The same holds for static methods.
Yes, of course you can define the static method in abstract class. you can call that static method by using abstract class,or by using child class who extends the abstract class. Also you can able to call static method through child class instance/object.
Pure Virtual Destructors in C++ The only difference between Virtual and Pure Virtual Destructor is, that pure virtual destructor will make its Base class Abstract, hence you cannot create object of that class. There is no requirement of implementing pure virtual destructors in the derived classes.
Abstract classes (apart from pure virtual functions) can have member variables, non-virtual functions, regular virtual functions, static functions, etc.
In C++, a static member function of a class cannot be virtual.
An abstract class is one in which there is a declaration but no definition
A pure abstract class in C++ is considered as an interface, too.
Hence, any constant declarations doesn't violate the purity of class abstractness. In IDL you can declare constants inside and outside of interfaces.
However, static members, constructors (even empty one), and a non-abstract destructor break the purity. So pure abstract class would looks like following
class C
{
public:
const std::string S = "Message";
virtual ~C() = 0;
virtual void V() = 0;
};
The C++ standard doesn't define what is a "pure abstract" class, nor is there any commonly accepted language-independent definition that fits all languages equally.
The definition 1 you quote doesn't make a lot of sense to me in the context of C++. What your teachers claim is more consistent with the language design. Use whatever definition is convenient and necessary. In any case the notion itself is not at all important.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With