亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

如何為嵌套在一個(gè)模板類(lèi)里面的類(lèi)添加友元?比如==函數(shù)。

原創(chuàng) 2016-10-21 11:41:38 873
摘要:template <typename> class Vector; template <typename T> bool operator==(const typename Vector<T>::const_iterator&, const typenam
template <typename> class Vector;
template <typename T>
bool operator==(const typename Vector<T>::const_iterator&, const typename Vector<T>::const_iterator&); // 友元聲明,簽名是這么寫(xiě)嗎?

template <typename T>
class Vector {
public:
    class const_iterator: {
        friend bool operator==(const const_iterator& lsh, const const_iteraotr& rhs);
    public:
    };
};


template <typename T>
bool operator==(const typename Vector<T>::const_iterator& lhs, const typename Vector<T>::const_iterator& rhs) { // 友元定義

}

如果直接將==友元在const_iterator里面定義,比較簡(jiǎn)單,直接寫(xiě)就行。但是我想在類(lèi)外定義時(shí),就不知道怎么寫(xiě)它的函數(shù)簽名了。

答:最好是這樣寫(xiě),你上面寫(xiě)的那種貌似很難實(shí)現(xiàn)

template <typename> struct Vector;

template <typename T>
struct Vector_const_iterator;

template <typename T>
bool operator==(const Vector_const_iterator<T>& lsh, const Vector_const_iterator<T>& rhs);

template <typename T>
struct Vector {
    typedef Vector_const_iterator<T> const_iterator;
};

template <typename T>
struct Vector_const_iterator {
    friend bool operator == <> (const Vector_const_iterator<T>& lsh, const Vector_const_iterator<T>& rhs);
};


template <typename T>
bool operator==(const Vector_const_iterator<T>& lsh, const Vector_const_iterator<T>& rhs) { 
    return true;
}


發(fā)佈手記

熱門(mén)詞條