p**e 发帖数: 335 | 1 template
class test
{
test();
~test();
friend bool operator== (const test &p1, const test &p2); //line 7
};
I will get:
test.h:7: warning: friend declaration 'bool operator==(const test&, const
test&)' declares a
non-template function
test.h:7: warning: (if this is not what you intended, make sure the function
template has already been
declared and add <> after the function name here) -Wno-non-template-friend
disables this warning
template
class t |
t****t 发帖数: 6806 | 2 write the friend as:
template
friend bool operator== (const test & p1, const test & p2);
7
const
【在 p**e 的大作中提到】 : template : class test : { : : test(); : ~test(); : friend bool operator== (const test &p1, const test &p2); //line 7 : }; : I will get: : test.h:7: warning: friend declaration 'bool operator==(const test&, const
|
p**e 发帖数: 335 | 3 thanks
template //line1
class test
{
test();
~test();
template friend bool operator==(const test& p1, const test& p2
); //line 9
};
it will be
test.h:9: error: declaration of 'class T'
test.h:1: error: shadows template parm 'class T' |
t****t 发帖数: 6806 | 4 稍改了一下
p2
【在 p**e 的大作中提到】 : thanks : template //line1 : class test : { : : test(); : ~test(); : template friend bool operator==(const test& p1, const test& p2 : ); //line 9 : };
|
p**e 发帖数: 335 | |
g****n 发帖数: 14 | 6 You should write:
template
class test
{
public:
test() {}
~test() {}
template <> friend bool operator== (const test &p1, const
test &p2); //line 7
};
In this case, only a specialized instance of operator== is the friend of
test.
If you write
class test
{
public:
test() {}
~test() {}
template friend bool operator== (const test &
p1, const test &p2); //line 7
};
All the instances of template operator= |
p**e 发帖数: 335 | 7 thank you very much!
that works |
p**e 发帖数: 335 | 8 thank you very much!
that works |