Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have following template code:

class ClassName{};

template <class T>
class TemplatePtr
{
public:
    void operator=(T* p)
    {

    }
};

class TemplatePtr_ClassName: public TemplateePtr<ClassName>
{
public:
    ~TempaltePtr_ClassName();
};


void Test()
{
    TemplatePtr_ClassName data;
    data = new ClassName;
}

but compile fails with error message (VS2008):

error C2679: binary '=' : no operator found which takes a right-hand operand of type >>'ClassName *' (or there is no acceptable conversion)

Why it won't work as I have defined an operator in the template base class?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
236 views
Welcome To Ask or Share your Answers For Others

1 Answer

It gets inherited. However, the compiler-generated assignment operator for TempaltePtr_ClassName hides the inherited operator. You can make it visible by adding

using TempaltePtr<ClassName>::operator=;

to your derived class.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...