Advertisement

识别261号项目为裸指针类型

阅读量:

1.判断是裸指针还是智能指针

复制代码
    class Object
    {
    private:
    	int value;
    public:
    	Object(int x = 0) :value(x)
    	{
    		cout << "create Object" << this << endl;
    	}
    };
    template<class T>
    struct my_class
    {
    	static const bool value = true;
    };
    template<class T>
    struct my_class<T*>
    {
    	static const bool value = false;
    };
    template<class T>
    struct my_class<const T*>
    {
    	static const bool value = false;
    };
    template<class T>
    void fun(T& a)
    {
    	if (my_class<T>::value)
    	{
    		cout << "智能指针" << endl;
    	}

全部评论 (0)

还没有任何评论哟~