Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How to fix "Warning: should not initialize a non-const reference with a temporary"?

Reply
Thread Tools

How to fix "Warning: should not initialize a non-const reference with a temporary"?

 
 
qazmlp
Guest
Posts: n/a
 
      05-06-2004
// Test.C
Line-300: namespace
Line-301: {
Line-302: std::vector<std::string> vecaNS ;
Line-303: }

The 'SUN Forte 7 C++ Compiler' reports the following warning for the
above code:
"/advantage/hlri_tools/sol/SUNWspro/prod/include/CC/Cstd/./vector",
line 318: Warning: should not initialize a non-const reference with a
temporary.
"Test.C", line 302: Where: While instantiating
"std::vector<std::basic_string<char, std::char_traits<char>,
std::allocator<char>>, std::allocator<std::basic_string<char,
std::char_traits<char>, std::allocator<char>>>>::~vector()".
"Test.C", line 302: Where: Instantiated from non-template code.

Kindly help to fix this warning.
 
Reply With Quote
 
 
 
 
Sharad Kala
Guest
Posts: n/a
 
      05-06-2004

"qazmlp" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) m...
> // Test.C
> Line-300: namespace
> Line-301: {
> Line-302: std::vector<std::string> vecaNS ;
> Line-303: }
>
> The 'SUN Forte 7 C++ Compiler' reports the following warning for the
> above code:
> "/advantage/hlri_tools/sol/SUNWspro/prod/include/CC/Cstd/./vector",
> line 318: Warning: should not initialize a non-const reference with a
> temporary.


Well the culprit line is 318 which you haven't shown.
Anyways the error message is self-explanatory, it is illegal as per standard C++
to initialize a non-const reference with an rvalue.
Some compilers offer it as extension but that's unportable.


 
Reply With Quote
 
 
 
 
Buster
Guest
Posts: n/a
 
      05-06-2004
Sharad Kala wrote:
> "qazmlp" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) m...
>
>>// Test.C
>>Line-300: namespace
>>Line-301: {
>>Line-302: std::vector<std::string> vecaNS ;
>>Line-303: }
>>
>>The 'SUN Forte 7 C++ Compiler' reports the following warning for the
>>above code:
>>"/advantage/hlri_tools/sol/SUNWspro/prod/include/CC/Cstd/./vector",
>>line 318: Warning: should not initialize a non-const reference with a
>>temporary.

>
> Well the culprit line is 318 which you haven't shown.


No, it's line 308 of <vector>.

My advice to the OP is to get a better compiler.

--
Regards,
Buster.
 
Reply With Quote
 
Sharad Kala
Guest
Posts: n/a
 
      05-06-2004

"Buster" <(E-Mail Removed)> wrote in message
news:c7csqr$7rs$(E-Mail Removed)...
> Sharad Kala wrote:
> > "qazmlp" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed) m...
> >

[snip]
> >>"/advantage/hlri_tools/sol/SUNWspro/prod/include/CC/Cstd/./vector",
> >>line 318: Warning: should not initialize a non-const reference with a
> >>temporary.

> >
> > Well the culprit line is 318 which you haven't shown.

>
> No, it's line 308 of <vector>.


No, I think it's line 318 of <vector>


 
Reply With Quote
 
Buster
Guest
Posts: n/a
 
      05-06-2004
Sharad Kala wrote:
>>>>"/advantage/hlri_tools/sol/SUNWspro/prod/include/CC/Cstd/./vector",
>>>>line 318: Warning: should not initialize a non-const reference with a
>>>>temporary.
>>>
>>>Well the culprit line is 318 which you haven't shown.

>>
>>No, it's line 308 of <vector>.

>
> No, I think it's line 318 of <vector>


Quite right.

--
Regards,
Buster.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Xah's Edu Corner: The Concepts and Confusions of Pre-fix, In-fix, Post-fix and Fully Functional Notations Xah Lee Perl Misc 21 03-21-2006 07:02 AM
Xah's Edu Corner: The Concepts and Confusions of Pre-fix, In-fix, Post-fix and Fully Functional Notations Xah Lee Python 23 03-21-2006 07:02 AM
Xah's Edu Corner: The Concepts and Confusions of Pre-fix, In-fix, Post-fix and Fully Functional Notations Xah Lee Java 22 03-21-2006 07:02 AM
if instance variable get initialize after assigning some values or after constructor then when does static variable get initialize Tony Morris Java 3 02-04-2006 08:39 AM



Advertisments