virtual void foo() = 0 {};
Good morning. Is there any technical reason why
virtual void foo() = 0 {};
is not allowed? The grammar can be adjusted, and parsers seem to deal fine with it: VC++ even allows this as an extension.
I'd propose to adjust function-definition to include pure-specifiers. Would such a proposal be successful?
--
.~. In my life God comes first.... /V\ but Linux is pretty high after that :-D /( )\ Francis (Grizzly) Smit ^^-^^ http://www.smit.id.au/ -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GM/CS/H/P/S/IT/L d- s+:+ a++ C++++ UL++++$ P++ L+++$ E--- W++ N W--- M-- V-- PE- PGP t+ 5-- X-- R- tv b++++ D- G e++ h+ y? ------END GEEK CODE BLOCK------ http://www.geekcode.com/
On 22/04/15 19:55, Columbo wrote:
Good morning. Is there any technical reason why
virtual void foo() = 0 {};
what does this mean ??
foo.
virtual ~MyClass() = 0 = default;
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
Hi,I don’t see the point in this: the ”=0” part says that you will not provide animplementation for this class and then you add an empty one?
A pure virtual function need be defined only if called with, or as if with (12.4), the qualified-id syntax (5.1).
Evidently, I was wrong. The closest I’ve ever come to this was a
software that emitted a “pure virtual function called”-exception.
//Henrik
--
This defines a pure virtual member functionfoo.
This syntax could be particularly useful for destructors:
virtual ~MyClass() = 0 = default;
Looks ridiculous, yes, but that is compensated for by not having to provide a definition outside the class one.
2015-04-22 16:32 GMT+02:00 Nevin Liber <ne...@eviloverlord.com>:
> On 22 April 2015 at 06:01, Columbo <r....@gmx.net> wrote:
>> virtual ~MyClass() = 0 = default;
> Why can't this particular use case (not being able to
> instantiate the base class) be done today with protected constructors?
I am not sure whether this is *the* usecase I have in mind for =0 on
destructors. My prime usecase for it would be to make a class abstract
without having the programmer of the derived class to write an
implementation of the method (the compiler does it itself).
You still need a virtual destructor to have the class be polymorphic> Again, why don't protected constructors cover this case? I'm just not
> seeing it.
>
and allow delete through base class ptr. With the "=0" you get both
with only one declaration.
I don't know. Not having to write
class MyBaseClass {
protected:
MyBaseClass();
MyBaseClass(const MyBaseClass&);
public:
virtual ~MyBaseClass();
};
when you can simply write
class MyBaseClass {
virtual ~MyBaseClass() = 0;
};
sounds like a nice use case. And in the second way, you also
*actually* get an abstract class, and not just an approximation of it.
It should also be noted that a major ABI that at least GCC and Clang
use by default put the Vtable of a class into the TU where the first
virtual function was defined in.
--
struct A1 { virtual void f(); };
struct A2 { virtual void f() = 0; }
struct A1 { virtual void f(){} };
struct A1 { virtual void f(); };
inline void A1::f() {}
as
struct A1 { virtual void f() = 0 {}; };