C++ template operator overloading with different types

后端 未结 1 915
醉酒成梦
醉酒成梦 2020-12-11 11:02

The example below defines a basic podtype container class. Using this class a series of typedefs are then created which represent an OOP version of the basic podtype. The pr

相关标签:
1条回答
  • 2020-12-11 11:45

    You need a templated operator + because you are trying to add different types:

    template <typename U>
    PodObject<T> operator+= (PodObject<U> const &rhs){
        this->_value = rhs._value;
        return *this;
    }
    

    That said, the whole code looks like an anti-pattern. Your “OOP version of the basic podtype” is not a meaningful, nor generally useful, concept.

    0 讨论(0)
提交回复
热议问题