奇怪的编译器消息 [英] strange compiler message
问题描述
您好,
我想知道是否有人遇到过以下g ++编译器错误消息。
我不记得曾经见过它。我解决了我的问题,但是我仍然不确定
这个消息是什么。任何
想法?
错误:无限制初始化非const引用
类型''Foo&''来自临时类型''Foo''
谢谢,
Neil
Hello,
I wonder whether anyone has ever come across
the following g++ compiler error message. I
don''t recall ever seeing it before. I solved
my problem but I am still not sure about
what this message is all about. Any
ideas?
error: invalid initialization of non-const reference of
type ''Foo&'' from a temporary of type ''Foo''
Thanks,
Neil
推荐答案
您需要发布代码以确切知道原因,但我会猜测您是否传递了一个临时对象,如Foo() ,
作为函数的参数,这是一个非const参数,
你正在做f(Foo())。
标准不允许你修改临时对象像Foo(),所以
这就是编译器紧握的原因。
dave
" Neil Zanella" < NZ ****** @ cs.mun.ca>在消息中写道
news:b6 ************************** @ posting.google.c om ...
You need to post the code to know exactly why, but I''d
guess that you are passing a temporary object like Foo(),
as a parameter to a function which is a non const parameter,
ie, void foo( Foo& f ) instead of void foo( const Foo& f )
and you are doing f( Foo() ).
The standard doesn''t allow you to modify tempoary objects like Foo(), so
that is why the compiler is griping.
dave
"Neil Zanella" <nz******@cs.mun.ca> wrote in message
news:b6**************************@posting.google.c om...
您好,
我想知道是否有人遇到过以下g ++编译器错误消息。我以前不记得见过它。我解决了我的问题,但我仍然不确定
这条消息是什么。任何
想法?
错误:从'Foo'类型的临时类型''Foo&''中非const引用无效初始化
谢谢,
Neil
Hello,
I wonder whether anyone has ever come across
the following g++ compiler error message. I
don''t recall ever seeing it before. I solved
my problem but I am still not sure about
what this message is all about. Any
ideas?
error: invalid initialization of non-const reference of
type ''Foo&'' from a temporary of type ''Foo''
Thanks,
Neil
Dave Townsend写道:
Dave Townsend wrote:
您需要发布代码才能确切知道原因,但我会猜测您是否将一个临时对象(如Foo(),
作为参数传递给一个非const参数的函数,
ie,void foo(Foo& f)而不是void foo(const Foo& f)
你正在做f(Foo())。
标准不允许你修改像Foo()那样的时态对象,所以
就是编译器紧握的原因。
You need to post the code to know exactly why, but I''d
guess that you are passing a temporary object like Foo(),
as a parameter to a function which is a non const parameter,
ie, void foo( Foo& f ) instead of void foo( const Foo& f )
and you are doing f( Foo() ).
The standard doesn''t allow you to modify tempoary objects like Foo(), so
that is why the compiler is griping.
挑剔:
你的意思是它不允许将非常量引用绑定到临时的
。
(它允许你修改用户定义的非const临时对象/>
类型,因为你可以在这些对象上调用成员函数。)
Denis
Nitpicking:
You meant it doesn''t allow a non-constant reference to be bound
to a temporary.
(It does allow you to modify non-const temporary objects of user-defined
types, since you can call member functions on such objects).
Denis
" Denis Remezov" <音响*************** @ yahoo.removethis.ca>写道:
"Denis Remezov" <fi***************@yahoo.removethis.ca> wrote...
Dave Townsend写道:
Dave Townsend wrote:
您需要发布代码以确切知道原因,但我会猜测你传递一个像Foo(),
这样的临时对象作为一个非const参数的函数的参数,
,即void foo(Foo& f)而不是void foo( const foo& f)
你正在做f(Foo())。
标准不允许你修改像Foo()这样的时态对象,所以
这就是编译器紧握的原因。
挑剔:
你的意思是它不允许非常量的引用被绑定
(它确实允许你修改用户定义的
类型的非const临时对象,因为你可以在这些对象上调用成员函数)。
You need to post the code to know exactly why, but I''d
guess that you are passing a temporary object like Foo(),
as a parameter to a function which is a non const parameter,
ie, void foo( Foo& f ) instead of void foo( const Foo& f )
and you are doing f( Foo() ).
The standard doesn''t allow you to modify tempoary objects like Foo(), so
that is why the compiler is griping.
Nitpicking:
You meant it doesn''t allow a non-constant reference to be bound
to a temporary.
(It does allow you to modify non-const temporary objects of user-defined
types, since you can call member functions on such objects).
挑剔:
(它允许你修改用户定义类型的临时对象
因为你可以调用非const成员这些物体的功能)。
丹尼斯
Nitpicking:
(It does allow you to modify temporary objects of user-defined types
since you can call non-const member function on such objects).
Denis
Victor
Victor
这篇关于奇怪的编译器消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!