3

I am trying to create a non-copyable class and inherit it to myclass. Here's how the code looks:

template<class T>
struct NonCopyable
{
protected:
    NonCopyable() {}
private:
    NonCopyable(const NonCopyable& x) = delete;  
    T& operator=(const T& x) = delete;
};

The delete allows a third mechanism through re-use of the delete keyword to define a function as “deleted.”

class Myclass : public RefCnt, private NonCopyable<Myclass>
{
    virtual unsigned int GetID() = 0;
    virtual bool Serialize() = 0;
};

Now when I try this, I get an error on my VS 2010 as: 'NonCopyable' : pure specifier or abstract override specifier only allowed on virtual function.

The compiler is thinking I am trying to create a non virtual function as pure. Can somebody please explain why? I can solve the above problem, by removing "delete" keyword.

Flexo
  • 87,323
  • 22
  • 191
  • 272
jan
  • 137
  • 2
  • 6
  • 3
    I suspect the answers is: `= delete` isn't yet supported by your compiler. I don't have VS 2010 to hand to confirm though. – Flexo Feb 27 '12 at 00:03
  • I thought the same, but how do I verify that? – jan Feb 27 '12 at 00:06
  • 3
    If you're using `= delete`, then just use it directly instead of inheriting from a class that uses it. And yes, VS10 doesn't support that. – Cat Plus Plus Feb 27 '12 at 00:06
  • Why is your `NonCopyable` a template? And as CatPP says, with C++11 and `delete` you don't really need this crutch of a construction anymore. It was only good when you didn't have a *semantic* way to express your intent of making a class noncopyable. – Kerrek SB Feb 27 '12 at 00:11
  • This question made me spawn this related one: http://stackoverflow.com/questions/9458741 – Emile Cormier Feb 27 '12 at 00:41
  • @Kerek SB, Yes you are right. I did that first and as it did not work, I tried isolating it by making a new templatized class. Finally, I got to know that VS10 doesnt support it. Thanks for all the inputs though. – jan Feb 27 '12 at 01:15

1 Answers1

4

You can see from this post that vs2010 does not support defaulted or deleted functions. For that matter neither will vc11

rerun
  • 25,014
  • 6
  • 48
  • 78