模板参数不能成为朋友 [英] template parameters cannot be friends
问题描述
你好,
你能建议我,为什么gcc 3.3.3无法编译这个:
模板< class T>
class Base
{
Base(){}
朋友T;
};
A类:虚拟公共基地< A>
{
公开:
A() {}
};
#g ++ test.cpp
test.cpp:6:错误:模板参数不能成为朋友
而CC,MS VisualC ++,gcc 2.95呢。
是否与C ++标准冲突?
如何更改代码产生这样的行为?我需要使用
模板
谢谢。
siddhu写道:
你好,
你能建议我,为什么gcc 3.3.3无法编译这个:
模板< class T>
类底座
{
Base(){}
朋友T;
};
A类:虚拟公共基地< A>
{
public:
A(){}
};
#g ++ test.cpp
test.cpp:6:错误:模板参数不能成为朋友
而CC,MS VisualC ++,gcc 2.95做。
是否与C ++冲突标准?
No.
如何更改代码以产生此类行为?我需要使用
模板
使''Base'的构造函数受到保护。
V
-
请在通过电子邮件回复时删除资金''A'
我没有回复顶部-posted回复,请不要问
4月18日下午4:14,Victor Bazarov < v.Abaza ... @ comAcast.netwrote:
siddhu写道:
您好,
你会建议我,为什么gcc 3.3.3无法编译这个:
template< class T>
类基地
{
基础(){}
朋友T;
};
A类:虚拟公共基地< A>
{
public:
A(){}
};
#g ++ test.cpp
test.cpp:6:错误:模板参数不能成为朋友
而CC,MS VisualC ++,gcc 2.95 do。
是否与C ++标准冲突?
No.
如何更改代码以产生此类行为?我需要使用
模板
使''Base'的构造函数受到保护。
V
-
请在通过电子邮件回复时删除资金''A'
我没有回复顶部-posted回复,请不要问 - 隐藏引用的文字 -
- 显示引用的文字 -
我想要A级是最后一堂课。这就是为什么我保留Base'的
构造函数是私有的。即使我保护它,它也不会被编译。
siddhu写道:
< blockquote class =post_quotes>
4月18日下午4:14,Victor Bazarov < v.Abaza ... @ comAcast.netwrote:
> siddhu写道:
>>你好,
你会建议我,为什么gcc 3.3.3无法编译这个:
模板< class T>
类基地
{
Base(){}
朋友T;
};
A类:虚拟公共基地< A>
{
公开:
A(){ }
};
#g ++ test.cpp
test.cpp:6:错误:模板参数不能成为朋友
CC,MS VisualC ++,gcc 2.95做。
它与C ++标准有冲突吗?
No.
>>如何更改代码以产生此类行为?我需要使用
模板
使''Base'的构造函数受到保护。
V
-
请在通过电子邮件回复时删除资本''A'
我不回复最热门的回复,请不要问 - 隐藏引用的文字 -
- 显示引用的文字 -
我希望A班成为最后一堂课。这就是为什么我保留Base'的
构造函数是私有的。即使我让它受到保护,它也不会被编译成
。
这就是为什么你说你想*做*的原因。您的问题是常见问题解答。
http://www.parashift.com/c++-faq-lit...html#faq-23.11
Hello,
would you suggest to me, why gcc 3.3.3 can not compile this:
template<class T>
class Base
{
Base(){}
friend T;
};
class A:virtual public Base<A>
{
public:
A(){}
};
# g++ test.cpp
test.cpp:6: error: template parameters cannot be friends
while CC,MS VisualC++, gcc 2.95 do.
Does it conflict with C++ standard?
How can i change code to produce such behaviour? I need to use
template
Thank you.
siddhu wrote:Hello,
would you suggest to me, why gcc 3.3.3 can not compile this:
template<class T>
class Base
{
Base(){}
friend T;
};
class A:virtual public Base<A>
{
public:
A(){}
};
# g++ test.cpp
test.cpp:6: error: template parameters cannot be friends
while CC,MS VisualC++, gcc 2.95 do.
Does it conflict with C++ standard?No.
How can i change code to produce such behaviour? I need to use
templateMake the constructor of ''Base'' protected.
V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask
On Apr 18, 4:14 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:siddhu wrote:Hello,
would you suggest to me, why gcc 3.3.3 can not compile this:
template<class T>
class Base
{
Base(){}
friend T;
};
class A:virtual public Base<A>
{
public:
A(){}
};
# g++ test.cpp
test.cpp:6: error: template parameters cannot be friends
while CC,MS VisualC++, gcc 2.95 do.
Does it conflict with C++ standard?
No.
How can i change code to produce such behaviour? I need to use
template
Make the constructor of ''Base'' protected.
V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask- Hide quoted text -
- Show quoted text -I want class A to be final class. Thats why I have kept Base''s
constructor is private. Even if I make it protected ,it is not going
to get compiled.
siddhu wrote:On Apr 18, 4:14 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:>siddhu wrote:>>Hello,
would you suggest to me, why gcc 3.3.3 can not compile this:
template<class T>
class Base
{
Base(){}
friend T;
};
class A:virtual public Base<A>
{
public:
A(){}
};
# g++ test.cpp
test.cpp:6: error: template parameters cannot be friends
while CC,MS VisualC++, gcc 2.95 do.
Does it conflict with C++ standard?No.
>>How can i change code to produce such behaviour? I need to use
templateMake the constructor of ''Base'' protected.
V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask- Hide quoted text -
- Show quoted text -
I want class A to be final class. Thats why I have kept Base''s
constructor is private. Even if I make it protected ,it is not going
to get compiled.This is why you say what you *want* to do. Your question is a FAQ.
http://www.parashift.com/c++-faq-lit...html#faq-23.11
这篇关于模板参数不能成为朋友的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!