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

Discussion in 'C++' started by qazmlp, May 6, 2004.

  1. qazmlp

    qazmlp Guest

    // 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.
    qazmlp, May 6, 2004
    #1
    1. Advertising

  2. qazmlp

    Sharad Kala Guest

    "qazmlp" <> wrote in message
    news:...
    > // 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.
    Sharad Kala, May 6, 2004
    #2
    1. Advertising

  3. qazmlp

    Buster Guest

    Re: How to fix "Warning: should not initialize a non-const referencewith a temporary"?

    Sharad Kala wrote:
    > "qazmlp" <> wrote in message
    > news:...
    >
    >>// 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.
    Buster, May 6, 2004
    #3
  4. qazmlp

    Sharad Kala Guest

    "Buster" <> wrote in message
    news:c7csqr$7rs$...
    > Sharad Kala wrote:
    > > "qazmlp" <> wrote in message
    > > news:...
    > >

    [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> :)
    Sharad Kala, May 6, 2004
    #4
  5. qazmlp

    Buster Guest

    Re: How to fix "Warning: should not initialize a non-const referencewith a temporary"?

    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.
    Buster, May 6, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken Cox [Microsoft MVP]
    Replies:
    4
    Views:
    5,621
    Ken Cox [Microsoft MVP]
    Aug 28, 2003
  2. Patrick Philippot
    Replies:
    0
    Views:
    461
    Patrick Philippot
    Apr 14, 2006
  3. Xah Lee
    Replies:
    22
    Views:
    1,126
    Tim Roberts
    Mar 21, 2006
  4. Xah Lee
    Replies:
    23
    Views:
    1,068
    Tim Roberts
    Mar 21, 2006
  5. Xah Lee
    Replies:
    21
    Views:
    790
    Tim Roberts
    Mar 21, 2006
Loading...

Share This Page