473,394 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 3489

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Dave Smithz | last post by:
Hi, In summary: I want to a form to submit information via a HTTP POST, however, when using Internet Explorer I want to be able to use the back button and all the information retained....
2
by: Liang | last post by:
Hi, I use "defined $r_libs->{$name}" to check first if a key exists in a hash table. But Perl gives a warning WHENEVER the key exists: "Use of uninitialized value". Would u please help to...
4
by: bingfeng | last post by:
I have some codes generated by perl, in which initialize some huge struct,such as PARA TOS_network_spantree_set_0_para_0 = { "vlan", emNUM, NULL, "", "configuration on a designated vlan",...
40
by: Dave Hansen | last post by:
Please note crosspost. Often when writing code requiring function pointers, it is necessary to write functions that ignore their formal parameters. For example, a state machine function might...
32
by: Stephen | last post by:
Is there a standard way to remove the warning that a C compiler might produce from the statement: if (a = b) {} I don't want to do: if ((a = b) != 0) {} Because my "a = b" is actually...
7
by: Olaf Baeyens | last post by:
I am testing VC++ 2005 and I get this warning: "warning C4996: 'strncpy' was declared deprecated" Does that mean that they might be phased out in VC++ 2006 or higher? Or does an alternative...
3
by: Chuck Cobb | last post by:
I'm doing a CSharp project in VS2005 and I'm getting some strange warning messages. The problem is that the warning messages don't link to anything in my code so they are very difficult to track...
19
by: lawrence k | last post by:
How can I find out where my script is outputting to the screen for the first time? My error logs are full of stuff like this: PHP Warning: session_start(): Cannot send session cache...
5
by: Torben Laursen | last post by:
I am writing a COM in C# using visual studio 2005 and VSTO. Inside the code I use some support classes that are generic but they are not used in the inferface of the COM. However I still get a...
13
by: Rex Mottram | last post by:
I'm using an API which does a lot of callbacks. In classic callback style, each routine provides a void * pointer to carry user-defined data. Sometimes, however, the user-defined pointer is not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.