compilation warning

S

Subrat

Hello,

I am getting complation warning saying,
warning : returning reference to temporary.

The code from which it is coming:
vector<bool> a_oObj;
This vector is filled with all boolean values
Then when I want to check a condition on this
for loop
int i = 0;
if(obj == true) //warning comes here

Thanks in Advance,

Subrat
 
A

anon

Subrat said:
Hello,

I am getting complation warning saying,
warning : returning reference to temporary.

The code from which it is coming:
vector<bool> a_oObj;
This vector is filled with all boolean values
Then when I want to check a condition on this
for loop
int i = 0;
if(obj == true) //warning comes here

Thanks in Advance,

Subrat


Your example doesn't compile and I do not see a return statement,
therefore can't say anything.

Next function would produce that warning:

bool& f()
{
bool a = true;
return a;
}
 
S

Subrat

The example is not a perfect piece of code. Thats an abstract code

anon said:
Subrat said:
Hello,

I am getting complation warning saying,
warning : returning reference to temporary.

The code from which it is coming:
vector<bool> a_oObj;
This vector is filled with all boolean values
Then when I want to check a condition on this
for loop
int i = 0;
if(obj == true) //warning comes here

Thanks in Advance,

Subrat


Your example doesn't compile and I do not see a return statement,
therefore can't say anything.

Next function would produce that warning:

bool& f()
{
bool a = true;
return a;
}
 
T

tony_in_da_uk

anon said:
Subrat said:
Hello,
I am getting complation warning saying,
warning : returning reference to temporary.
The code from which it is coming:
vector<bool> a_oObj;
This vector is filled with all boolean values
Then when I want to check a condition on this
for loop
int i = 0;
if(obj == true) //warning comes here
Thanks in Advance,
Subrat

Your example doesn't compile and I do not see a return statement,
therefore can't say anything.

The example is not a perfect piece of code. Thats an abstract code


It's not sufficient to explain the compiler warning. I suggest you
post your actual code.

Tony
 
P

Pascal J. Bourguignon

Subrat said:
Hello,

I am getting complation warning saying,
warning : returning reference to temporary.

The code from which it is coming:
vector<bool> a_oObj;
This vector is filled with all boolean values
Then when I want to check a condition on this
for loop
int i = 0;
if(obj == true) //warning comes here


Other have mentionned that this is no compilable code. But in any
case, you show us a variable named a_oObj, and then you refer a
variable named obj.
 
R

raicuandi

Hello,

I am getting complation warning saying,
warning : returning reference to temporary.

The code from which it is coming:
vector<bool> a_oObj;
This vector is filled with all boolean values
Then when I want to check a condition on this
for loop
int i = 0;
if(obj == true) //warning comes here

Thanks in Advance,

Subrat


Please post the code of the function in which you get the warning.
You must be doing what anon said, which is,

vector<bool>& myFunc() // note the "&", if you remove that, its a
quick-fix that will work, although its one damn slow copy-constructor
{
...
vector<bool> v;
return v; // warning; accessing the returned value should either
crash or read garbage
}

Cheers!
-- raicuandi
 

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

Forum statistics

Threads
474,171
Messages
2,570,935
Members
47,472
Latest member
KarissaBor

Latest Threads

Top