国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

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

Original 2016-10-21 11:41:38 870
abstract: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&); // 友元聲明,簽名是這么寫嗎?

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)單,直接寫就行。但是我想在類外定義時(shí),就不知道怎么寫它的函數(shù)簽名了。

答:最好是這樣寫,你上面寫的那種貌似很難實(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;
}


Release Notes

Popular Entries