开发者

c++. compile error. am trying to add friend template function with enum template parameter

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.


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>();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜