Archived

This topic is now archived and is closed to further replies.

Kevinator

Lvalue?

Recommended Posts

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..

Share this post


Link to post
Share on other sites
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 ]

Share this post


Link to post
Share on other sites