Home > Back-end >  Is there a way to get rid of template <class T> on operator overloading?
Is there a way to get rid of template <class T> on operator overloading?

Time:08-11

I would like to know if there is a way to get rid of template <class TI> to make my code more clear (I have an overload for every logic operator, not only operator==). Only in C 98, please.

template <class T> 
class iter
{
public:
    // some stuff
private:
    template <class TI>
    friend bool operator == (const iter<TI> &lhs, const iter<TI> &rhs);
};

template <class T>
bool operator == (const iter<T> &lhs, const iter<T> &rhs) {
    return (lhs._ptr == rhs._ptr);
}

CodePudding user response:

Within template<class T> class iter, you may simply use iter to mean iter<T>.

template <class T> 
class iter
{
    public:
    // some stuff
    private:
        friend bool operator == (const iter& lhs, const iter& rhs);
        {
            return (lhs._ptr == rhs._ptr);
        }
};
  • Related