Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utility.h 编译报错 #19

Open
metahys opened this issue Aug 24, 2016 · 1 comment
Open

utility.h 编译报错 #19

metahys opened this issue Aug 24, 2016 · 1 comment

Comments

@metahys
Copy link

metahys commented Aug 24, 2016

g++ 4.2.1

../Utility.h:31:19: error: declaration of 'T1' shadows template parameter
template <class T1, class T2>

template<class T1, class T2>
    struct pair{
    public:
        typedef T1 first_type;
        typedef T2 second_type;
    public:
        T1 first;
        T2 second;
    public:
        pair(){}
        template<class U, class V> 
        pair(const pair<U, V>& pr);
        pair(const first_type& a, const second_type& b);
        pair& operator= (const pair& pr);
        void swap(pair& pr);
    public:
        template <class T1, class T2>
        friend bool operator== (const pair<T1, T2>& lhs, const pair<T1, T2>& rhs);
        template <class T1, class T2>
        friend bool operator!= (const pair<T1, T2>& lhs, const pair<T1, T2>& rhs);
        template <class T1, class T2>
        friend bool operator<  (const pair<T1, T2>& lhs, const pair<T1, T2>& rhs);
        template <class T1, class T2>
        friend bool operator<= (const pair<T1, T2>& lhs, const pair<T1, T2>& rhs);
        template <class T1, class T2>
        friend bool operator>  (const pair<T1, T2>& lhs, const pair<T1, T2>& rhs);
        template <class T1, class T2>
        friend bool operator>= (const pair<T1, T2>& lhs, const pair<T1, T2>& rhs);
        template <class T1, class T2>
        friend void swap(pair<T1, T2>& x, pair<T1, T2>& y);

    };

应该是友元函数的模版形参使用T1、T2会屏蔽外层的T1、T2?
Accessing template parameters of the member templates

@fateorder
Copy link

恩,改完就能通过了

    public:
        template <class U, class V>
        friend bool operator== (const pair<U, V>& lhs, const pair<U, V>& rhs);
        template <class U, class V>
        friend bool operator!= (const pair<U, V>& lhs, const pair<U, V>& rhs);
        template <class U, class V>
        friend bool operator<  (const pair<U, V>& lhs, const pair<U, V>& rhs);
        template <class U, class V>
        friend bool operator<= (const pair<U, V>& lhs, const pair<U, V>& rhs);
        template <class U, class V>
        friend bool operator>  (const pair<U, V>& lhs, const pair<U, V>& rhs);
        template <class U, class V>
        friend bool operator>= (const pair<U, V>& lhs, const pair<U, V>& rhs);
        template <class U, class V>
        friend void swap(pair<U, V>& x, pair<U, V>& y);

    };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants