views:

107

answers:

4

Hello! I want to create in my project class "Screen", "Graphics", "Font" and "Environment", but when I type these names and hit enter I get message: "Screen" is reserved class name or "Environment" is reserved class name. I don't want to make CScreen or ScreenC or something like that :/ I have Visual Stuido 2010. Is there any way to fix this ?

A: 

You either need to completely not #include these classes into your project or make a namespace for your classes and then use that namespace when you need to resolve.

If you want other programmers to use your code, they might get confused that you are reusing names of classes that they already know, so it would be better to come up with a prefix for your classes, perhaps signifying the project name.

Lou Franco
+6  A: 

i think using namespace is the answer.

Tristan Su
+1  A: 

What do you mean by "I type these names and hit enter"? Is this Class Wizard message? In this case just create h and cpp files manually. I don't know any C++ feature that doesn't allow to use these names for a class. Of course, in the case of name collision, use namespace.

Alex Farber
A: 

I find solution: I can add separately Graphics.cpp and Graphics.h, Environment.cpp and .. etc :/ But I still don't know why I can't use "add class" :/

PiTeReK
You really need to study namespaces, they are the answer.
JustBoo
Why namespaces ? Look http://img814.imageshack.us/i/screenshotec.png/ I don't write any code yet in these files.
PiTeReK
I believe the IDE itself is stopping you from using those names. Right now it might not seem important, but in "corporate" projects file names have a way of never "dying" and of propagating. You live with them "forever." What we name things does matter.
JustBoo
Well, my guess was correct: your are talking about Class Wizard. Create class with another name (like _Environment), and then use Find and Replace function to correct results.
Alex Farber