Thread: Embarassingly Stupid Question

  1. #1
    Registered User samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Newport
    Posts
    382

    Embarassingly Stupid Question

    Despite having been programming in C++ for about a decade, I've never got my head around 'proper' multi-file projects. My projects have been either completely monolithic or have been linked by #including .cpp files (which I understand is not good practice).

    The thing is, every time I try to do it properly I get errors. I have attatched a simple project to demonstrate what I mean (MSVC++ 6.0). The .h file is included and the .cpp file has been added to the project but it STILL won't compile.

    Maybe you can help.

    http://s40.yousendit.com/d.aspx?id=2...91CA86CY0MEYCK
    Current Setup: Win 10 with Code::Blocks 17.12 (GNU GCC)

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Let's assume your header to be named "point.h" instead of "c.h". Then #include "point.h" in c.cpp like it is in t.cpp.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    1) Put your declarations in a .h file.

    2) Include the .h file in any file that uses the names declared in the .h file.

    An include statement just causes the contents of the specified file to replace the include statement. So, when you include the .h file at the top of a .cpp file, the declarations get inserted in the .cpp file.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid Question Probably
    By Kyrin in forum C Programming
    Replies: 2
    Last Post: 05-07-2006, 12:51 AM
  2. Replies: 7
    Last Post: 11-04-2005, 12:17 AM
  3. Stupid Question
    By digdug4life in forum C++ Programming
    Replies: 22
    Last Post: 05-17-2005, 11:43 AM
  4. stupid, stupid question
    By xelitex in forum C++ Programming
    Replies: 5
    Last Post: 12-22-2004, 08:22 PM
  5. Stupid question: What does Debugger do?
    By napkin111 in forum C++ Programming
    Replies: 6
    Last Post: 05-02-2002, 10:00 PM