0

When I try to compile this (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() { }

I get

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

Why?

[disregard: if i don't include this line, stack overflow says i have too much code in my post when i save]

Paul Draper
  • 78,542
  • 46
  • 206
  • 285

1 Answers1

2

The compiler doesn't know that A<T>::B denotes a type so it tries to do multiplication there.

Use typename A<T>::B *x;

Karoly Horvath
  • 94,607
  • 11
  • 117
  • 176