0

Please help with the next code:

typedef enum {a1, a2, a3} E;

template<E e>
int foo() {
    return static_cast<int>(e);
}

class A {
    A() {};

    friend int foo<E e>();
};

The compiler says: error C2146: syntax erorr: missing "," before identifier "e"

I would be glad if someone could explain my mistake. Thanks.

artyom.stv
  • 2,097
  • 1
  • 24
  • 42

1 Answers1

2

If you want class A to befriend the function template foo(), you need to use:

template <E> friend int foo();

You can also befriend a particular instantiation of the function template foo():

friend int foo<a1>();
James McNellis
  • 348,265
  • 75
  • 913
  • 977