Pure virtual functions are delcared with the common syntax :
virtual f() = 0;
Yet, since c++11 there's a way to communicate the explicit non existence
of a (special) member function :
Mystruct() = delete; // eg default constructor
Why isn't this syntax extended to pure virtual functions in order to achieve uniformity in communicating such operations ? :
virtual f() = delete;
I know the obvious answer is because the Standard says so!
. I'm wondering about the reason(ing) behind this and whether there ever was a proposal (or an intention) for something like this.
You declare a pure virtual function by using a pure specifier ( = 0 ) in the declaration of a virtual member function in the class declaration. Class A is an abstract class. The compiler would not allow the function declarations A g() or void h(A) , declaration of object a , nor the static cast of b to type A .
Q) Which is the correct declaration of pure virtual function in C++ virtual void func() = 0; is the correct declaration.
¶ Δ A pure virtual function is a function that must be overridden in a derived class and need not be defined. A virtual function is declared to be “pure” using the curious =0 syntax.
2. Which is used to create a pure virtual function? d) ! Explanation: For making a method as pure virtual function, We have to append '=0' to the class or method.
Roughly speaking, the difference is that this:
virtual void f() = 0;
says "This class is abstract, and I may not have written an implementation of this member function" (though you are allowed to).
However, this:
void f() = delete;
says "This member function literally does not exist, and none shall pass."
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