Thread: placement of (.h) and (.cpp) files..!?

  1. #1
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279

    placement of (.h) and (.cpp) files..!?

    This has been on my mind for a while and finally it caught up to me by not working ....meaning:

    Can anyone explain and provide a best way of placing and especiall a way of including (.h) and (.cpp) files witing a project.

    What I mean is: I have a very simple class whose declaration is inside of (.h) file and it's implementation resides in (.cpp) file respecitvely.

    I was always under an impression that AT THE END (below all of the code) of my (.h) header file i must put:
    Code:
    #include"myclass.cpp"
    and in my (.cpp) implementation file i don't include anything...

    and finally in (for example) main.cpp file (where my main() function is) i include my (.h) header file only and NOT the (.cpp) file, which obviously is its implementation.

    Well, I always wanted to find out, however none of the books nor resourses illustrate its complete and proper use and exact placement.
    Most of the books that I have simply include (.h) header file inside of the (.cpp) implementation file, however they don't show what one must include in the main file where main() starts the program.

    To make the long story short, my compiler (Microsoft Visual C++ .NET) craps out and keeps saying that my class is NOT declared.????

    Can anyone please help??

    .....................
    matheo917

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    I was told that it is preferred that .cpp files not be included at the bottom of the .h file unless it is a templated class.

    Just #include the header file in the .cpp that includes main, and the .ccp implementation file should be included in the project.

  3. #3
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279
    Thank you very much, it works properly now.


    ps. I see now why I was frequently getting name clashes with STL when i was including my files the way i always was...

    .....................
    matheo917

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    you're welcome.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Get .cpp and .h files to communicate...
    By yaya in forum C++ Programming
    Replies: 6
    Last Post: 11-25-2008, 12:45 AM
  2. #include header files or .cpp files?
    By DoctorX in forum C++ Programming
    Replies: 3
    Last Post: 12-23-2006, 12:21 PM
  3. *.cpp and *.h files understanding
    By ElastoManiac in forum C++ Programming
    Replies: 4
    Last Post: 06-11-2006, 04:45 AM
  4. .cpp and .h files - organization
    By ChadJohnson in forum C++ Programming
    Replies: 4
    Last Post: 01-12-2006, 11:40 PM
  5. Class files (.h and .cpp
    By Todd in forum C++ Programming
    Replies: 7
    Last Post: 02-14-2002, 03:07 PM