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

Q

qazmlp

// 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.
 
S

Sharad Kala

qazmlp said:
// 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.
 
S

Sharad Kala

Buster said:
Sharad said:
[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> :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top