由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - C++ template question
相关主题
问个c++的template的问题C++ template question
[合集] 又被羞辱了一把... (转载)一个关于C++ template和overload的问题
一个C++ template的问题C++ template
a c++ questionC++ template function type
template 疑问C++ namespace 弱问
请问这是什么错误呀g++能够生成C++ template展开之后的代码么?
C++ linking 弱问 (one file)An object of A automatically converted to an object of B.
问几个C++面试题吧boost::function 的 syntax 问题
相关话题的讨论汇总
话题: test话题: template话题: const话题: class话题: operator
进入Programming版参与讨论
1 (共1页)
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
5
that is really strange
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
1 (共1页)
进入Programming版参与讨论
相关主题
boost::function 的 syntax 问题template 疑问
文一个简单的c++请问这是什么错误呀
谁给详细说一下这句C++ linking 弱问 (one file)
Cannot use my own container as the underlying container of a stack? (c++)问几个C++面试题吧
问个c++的template的问题C++ template question
[合集] 又被羞辱了一把... (转载)一个关于C++ template和overload的问题
一个C++ template的问题C++ template
a c++ questionC++ template function type
相关话题的讨论汇总
话题: test话题: template话题: const话题: class话题: operator