CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2006
    Posts
    144

    Classname vs. Filename

    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.

  2. #2
    Join Date
    Oct 2007
    Location
    Dubai UAE
    Posts
    9

    Re: Classname vs. Filename

    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.

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: Classname vs. Filename

    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.

  4. #4
    Join Date
    Aug 2006
    Posts
    144

    Re: Classname vs. Filename

    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?

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: Classname vs. Filename

    Quote Originally Posted by joebar
    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.

  6. #6
    Join Date
    Aug 2006
    Posts
    144

    Re: Classname vs. Filename

    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?

  7. #7
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: Classname vs. Filename

    You tell it to compile MyClass.cpp and it compiles whatever it finds in there.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured