468,537 Members | 1,844 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,537 developers. It's quick & easy.

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

// 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.
Jul 22 '05 #1
4 3274

"qazmlp" <qa********@rediffmail.com> wrote in message
news:db*************************@posting.google.co 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.
Jul 22 '05 #2
Sharad Kala wrote:
"qazmlp" <qa********@rediffmail.com> wrote in message
news:db*************************@posting.google.co 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.
Jul 22 '05 #3

"Buster" <no***@nowhere.com> wrote in message
news:c7**********@newsg1.svr.pol.co.uk...
Sharad Kala wrote:
"qazmlp" <qa********@rediffmail.com> wrote in message
news:db*************************@posting.google.co 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> :-)
Jul 22 '05 #4
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.
Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

40 posts views Thread by Dave Hansen | last post: by
32 posts views Thread by Stephen | last post: by
3 posts views Thread by Chuck Cobb | last post: by
13 posts views Thread by Rex Mottram | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.