views:

146

answers:

1

It isn't clear what happens if I delete a virtual method in C++0x:

 virtual int derive_func() = delete;

Does this mean this class and everything that inherits from it can not define/implement the derive_func() method? Or is this illegal/compile error?

+7  A: 

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2326.html#delete A deleted virtual function may not override a non-deleted virtual function and vice-versa. meaning its pretty useless (as i read it at least) the only valid use would be:

struct A{
     virtual void b() = delete;
};
struct B:A{
     virtual void b() = delete;
};

which is completely useless, since the function can never be called. for non virtual functions the use is more justified

EDIT to be completely clear this is the ONLY possible relation, children may not implement and you may not delete a non-deleted inherited virtual.

flownt
Weird. Maybe it forces methods to be obsolete? but still...
acidzombie24
does it force RTTI info to be stored?
KitsuneYMG
So it's like my deleted answer?
Klaim
@Klaim: how would i vieuw your deleted answer?
flownt
Copy/paste : My understanding (that might really be wrong, but please tell us if it is) is that:if it's a base class, it's exactly the same as declaring a virtual pure function ( using =0);if it's a child class and deriv_func() already have been declared has virtual, it's like making the child implementation null, making the child class an abstract class that force the child of this child class to implement the function....
Klaim
perhaps i misread it but as it stands in the answer it seems to imply that it's not exactly the same as =0 and g++ seems to confirm it though i can't get it to compile the example because it thinks i'm using the function(seems like a bug).
flownt