Jump to content
  • Advertisement
Sign in to follow this  
Kryogenik

left Operand must be l-value

This topic is 2804 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So yeah. I have an array that is a pointer to a pointer of my class CXFile, I declared it like this.

CXFile** Objects;

And allocated the array like this (Object Nums equals 2 BTW)

Objects=new CXFile* [ObjectNums];

I can use this array to control classes pointed to by the array, and it's pretty good. The only problem is that I don't know how to check if a certain value in the array has been initialized.

I know what the error means from a google search. It means that the number on the left side of the operator (== in my case) must be a variable or something, like you couldn't do this.

int=32

But I couldn't find anyone who had quite the same problem I'm having on google. I want to see if it is used yet because when you load an object in my little engine, you can specify a spot in the array you want it to be in, or you can set it to -1 and it will find a free spot to put it in for you. But I don't know how to check if a slot is free or not and thats the problem I'm having. I tried to use this to check if it was free, but it doesn't work and gives me the above error.

if(Objects[x]==0)
//Do stuff that would happen if the slot was free

What should I do? In a nutshell, how do I check if a spot in my CXFile** array has been used yet? Thanks for any help.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by CRYP7IK
Fairly certain you need to go like this:

*** Source Snippet Removed ***


Negative, unfortunately. Testcase:

$ cat test.cc
int main () {
class Foo{};
const int size = 42;
Foo **foos = new Foo*[size];

if (!foos[0]) {} // valid
if (foos[0] == 0) {} // valid
if (0 == foos[0]) {} // valid
if (foos[0] = 0) {} // <-- accidental assignment, still valid, but g++ gives a warning
//if (0 = foos[0]) {} // <-- accidental assignment to literal, invalid

delete [] foos;
}

$ g++ -Wall -Wextra test.cc
test.cc: In function int main():
test.cc:9:24: Warning: Suggest parentheses around assignment that is to be used as boolean expression
$

[note that I translated the warning from german to english]

The OP misses to tell us some important details :)

Share this post


Link to post
Share on other sites
Well, I don't want to post my whole engine, but this is the important part.

CXFile **Objects;
//CXFile is an abstract class if that is important
Objects=new CXFile* [2];
/*What I don't understand is this, how do I check if I have assigned a value to a certain spot in my array like this*/
if (Objects[1]==0)
//Do stuff that would happen if there is no value
//When I try that if statement, it gives me the error in the title of my thread

So what do I need to do, I tried if((*Objects)[x] == 0) and it gave me this error: binary '==' : no operator found which takes a left-hand operand of type 'CXFile' (or there is no acceptable conversion). And none of the things in phresnel's example work. Maybe there's something different about VC++. Thanks for any help.

Share this post


Link to post
Share on other sites


Here is some code


CXFile** Objects;
Objects = new CXFile* [ObjectNums];
for(int i =0; i< ObjectNums; i++){
Objects = 0;
}
// or you can do a memset(Objects, 0, sizeof(Objects*)*ObjectNums);
// now all values in your array are set to zero

Objects[5] = new CXFile();// allocate memory and place the point into array pos 5
// now you can test like this

if(Objects[5] ==0)
cout<<"Slot 5 has intialized memory ooh boy!"<<endl;
else
cout<<"Slot 5 is empty"<<endl;


Share this post


Link to post
Share on other sites

if(Objects[5] ==0)
cout<<"Slot 5 has intialized memory ooh boy!"<<endl;
else
cout<<"Slot 5 is empty"<<endl;



Isn't this backward?

Share this post


Link to post
Share on other sites
Quote:
Original post by Kryogenik
I got it working, thanks for the help.


You can help this thread by posting your solution.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!