error C2253: 'RefCounted<T>' : pure specifier or abstract override specifier only allowed on virtual

3 篇文章 0 订阅

环境:win7 32位,vs2010

源码:

#include <assert.h>

class RefCountedBase {
public:
	void ref()
	{
		++m_refCount;
	}

	bool hasOneRef() const
	{
		return m_refCount == 1;
	}

	unsigned refCount() const
	{
		return m_refCount;
	}

	void relaxAdoptionRequirement()
	{
	}

protected:
	RefCountedBase()
		: m_refCount(1)
	{
	}

	~RefCountedBase()
	{
	}

	// Returns whether the pointer should be freed or not.
	bool derefBase()
	{
		assert(m_refCount);
		unsigned tempRefCount = m_refCount - 1;
		if (!tempRefCount) {
			return true;
		}
		m_refCount = tempRefCount;
		return false;
	}
private:

	unsigned m_refCount;

};

template<typename T> class RefCounted : public RefCountedBase 
{
private: 
	RefCounted(const RefCounted&) = delete; 
	//RefCounted& operator=(const RefCounted&) = delete; 
public:
	void deref()
	{
		if (derefBase())
			delete static_cast<T*>(this);
	}

protected:
	RefCounted() { }
	~RefCounted()
	{
	}
};

int main()
{
	return 0;
}

报错:

1>d:\hbj\test\test0505\test0505\t0506_2.cpp(55): error C2253: 'RefCounted<T>' : pure specifier or abstract override specifier only allowed on virtual function
1>          d:\hbj\test\test0505\test0505\t0506_2.cpp(70) : see reference to class template instantiation 'RefCounted<T>' being compiled
1>

1>Build FAILED.

原因:c++0x新特色:使用或禁用对象的默认函数

vs2010不支持= delete,vs2013是支持的

解决:去掉= delete

参考:http://zh.wikipedia.org/wiki/C%2B%2B11

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值