ошибка: 'оператор []' не определен

У меня проблема с компиляцией с помощью g ++ фрагмента моей библиотеки, связанного с оператором [].

Я воссоздал ту же проблему с этим кодом:

    template<class A,class B> class X {
    public: 
        template<class C> X<C,B>& operator[]( const C& );
    };

    template<class A,class B,class C> class Y : public X<C,B> {
        friend X<C,B>& X<A,B>::template operator[]<C>( const C& );
    private:
        Y( X<A,B>& object , const C& index ) : X<C,B>() {};
    };

    template<class A,class B> template<class C> X<C,B>& X<A,B>::operator[]( const C& index ) {
        return *( new Y<A,B,C>( *this , index ) );
    }

    int main() {
        X<int,void> x;
        X<int,void>& y = x[2];
    }

g ++ завершает работу со следующей ошибкой:

./src/test.cpp: In instantiation of ‘Y<int, void, int>’:
./src/test.cpp:14:   instantiated from ‘X<C, B>& X<A, B>::operator[](const C&) [with C = int, A = int, B = void]’
./src/test.cpp:19:   instantiated from here
./src/test.cpp:8: error: ‘operator[]’ not defined
./src/test.cpp: In member function ‘X<C, B>& X<A, B>::operator[](const C&) [with C = int, A = int, B = void]’:
./src/test.cpp:19:   instantiated from here
./src/test.cpp:10: error: ‘Y<A, B, C>::Y(X<A, B>&, const C&) [with A = int, B = void, C = int]’ is private
./src/test.cpp:14: error: within this context

Я думаю, что проблема в другом объявлении 'operator []' в классе Y, но я не делаю ' не знаю, где это неправильно. Я пробовал искать сам, но ничего полезного не нашел. Кто-нибудь может мне помочь?

Спасибо, Джанни

8
задан Gianni Pisetta 18 August 2011 в 10:53
поделиться