Click to See Complete Forum and Search --> : Classname vs. Filename


joebar
October 18th, 2007, 04:03 AM
Hi,

when I create a class I chose the filename to be the same as the class name. Is that a must? What about capital/small letters? Can the filename all in small letters but the class name can be SomeThing with small and capital letters?

Thanks,
J.

**star**
October 18th, 2007, 04:12 AM
it is not a must that the class name(i think you mean the header file name) be the same as the file name , also it does not have to be in capital letters.
there is ni relation between the header file name and the original file name.

but if you come to programming using JAVA it is amust.

GCDEF
October 18th, 2007, 07:22 AM
It's not a must to name the classes and files the same, but when you get big projects with hundreds of classes and files, it'll certainly come in handy.

joebar
October 18th, 2007, 06:46 PM
One last question:

I understand that I can name the .h file as I want. Since it is known via include it is no problem to find that file. The implementation of my constructor and other functions is in a .cpp file, how is that found? I assume that the .h and the .cpp must have the exact same name. Is that correct?

GCDEF
October 18th, 2007, 07:31 PM
One last question:

I understand that I can name the .h file as I want. Since it is known via include it is no problem to find that file. The implementation of my constructor and other functions is in a .cpp file, how is that found? I assume that the .h and the .cpp must have the exact same name. Is that correct?

No. The file names really don't mean anything to the compiler and linker. Consistent and practical naming is done to help make the programmer's job easier.

joebar
October 19th, 2007, 09:48 AM
Okay but let's assume I have

main.cpp
aClass.h
MyClass.cpp

and a class called superClass. The compiler finds the header via the include, so aClass.h is found from main.cpp. How does the compiler know that the implementation of the superClass is found in MyClass.cpp?

GCDEF
October 19th, 2007, 10:02 AM
You tell it to compile MyClass.cpp and it compiles whatever it finds in there.