0

これをコンパイルしようとすると(g ++):

template<typename T>
struct A {

    struct B { };

    template<typename S>
    friend A<S>& operator +(A<S> const &, A<S> const &);
};

template<typename T>
A<T>& operator +(A<T> const &a, A<T> const &b) {
    A<T>::B *x;
    return a;
}

main() { }

私は得る

test.cpp: In function "A<T>& operator+(const A<T>&, const A<T>&)":
test.cpp:12:11: error: "x" was not declared in this scope

なんで?

[無視: この行を含めないと、スタック オーバーフローにより、保存時に投稿にコードが多すぎると表示されます]

4

1 に答える 1

2

コンパイラは が型を示していることを認識していないA<T>::Bため、そこで乗算を試みます。

使用するtypename A<T>::B *x;

于 2013-02-25T09:44:43.767 に答える