| | |
Case Expression Not Constant
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
When I try to compile this:
I get these errors:
I thought that things like "id" were constant because they're a litteral?
Any help would be appreciated.
PS. If you need more information on my problem, feel free to ask.
c++ Syntax (Toggle Plain Text)
void *BaseEnt::GetVar(char const *varname) { char name = *varname; switch(name) { case "id": return (void*)id; case "name": return (void*)name; case "count": return (void*)count; default: return (void*)NULL; } }
I get these errors:
C++ Syntax (Toggle Plain Text)
------ Build started: Project: Test Classes, Configuration: Debug Win32 ------ Compiling... classes.cpp c:\documents and settings\tom\my documents\visual studio 2008\projects\test classes\test classes\classes.cpp(25) : error C2051: case expression not constant c:\documents and settings\tom\my documents\visual studio 2008\projects\test classes\test classes\classes.cpp(27) : error C2051: case expression not constant c:\documents and settings\tom\my documents\visual studio 2008\projects\test classes\test classes\classes.cpp(29) : error C2051: case expression not constant c:\documents and settings\tom\my documents\visual studio 2008\projects\test classes\test classes\classes.cpp(33) : warning C4065: switch statement contains 'default' but no 'case' labels Build log was saved at "file://c:\Documents and Settings\tom\My Documents\Visual Studio 2008\Projects\Test Classes\Test Classes\Debug\BuildLog.htm" Test Classes - 3 error(s), 1 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I thought that things like "id" were constant because they're a litteral?
Any help would be appreciated.
PS. If you need more information on my problem, feel free to ask.
...
•
•
Join Date: Nov 2009
Posts: 1
Reputation:
Solved Threads: 0
-2
#3 Nov 2nd, 2009
try this
c++ Syntax (Toggle Plain Text)
void *BaseEnt::GetVar(char const *varname) { char name = *varname; switch(name) { case 'id': //use ' not " return (void*)id; case 'name': //use ' not " return (void*)name; case 'count': //use ' not " return (void*)count; default: return (void*)NULL; } }
![]() |
Similar Threads
- Time complexity of algorithm (Computer Science)
- put a struct type val in a FILE (C)
- Linker Error (C++)
- Problem with inheritance (C++)
- Tree traversal (Computer Science)
- Correct me If I'm wrong (C)
- Switch Statement, Fall-Through. (C)
- pointer (C)
Other Threads in the C++ Forum
- Previous Thread: Why is C++ so big?
- Next Thread: LPD3DXMESH vs ID3DXMesh
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamic dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library linkedlist linker list loop looping loops map math matrix memory microsoft newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template templates test text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets





