Lvalue?
When I try to compile some code, my compiler says ''Lvalue required''. Now, I know it will give you the error if you go like this:
27 = int num;
But here''s my code:
player.helmet.name = "Thin leather helmet";
Where ''name'' is a character array.. I''m baffled..
You cannot assign a new address ( and a "quoted string" really is an address ) to an array ( their address is fixed once and for all, technically your char name[] is a char* const name (const pointer to non-const data)).
Now, in C++, if you replace your char[] with a std::string (#include <string> you can do your assignment without any trouble.
In C, you''ll either need to use a const char* (in this case, the pointer will point to the address of the "quoted string" (the string itself is a constant)), or use strcpy() to copy the string over (no direct assignment with operator=() ).
Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
Now, in C++, if you replace your char[] with a std::string (#include <string> you can do your assignment without any trouble.
In C, you''ll either need to use a const char* (in this case, the pointer will point to the address of the "quoted string" (the string itself is a constant)), or use strcpy() to copy the string over (no direct assignment with operator=() ).
Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement