Thread: really dumb beginner question on include

  1. #1
    Registered User
    Join Date
    Nov 2003

    really dumb beginner question on include

    ok, i got this:

    a cpp file declaring a class, with it's header file containing function prototypes.

    another cpp file containing a new class of objects of the previous class with another header file for it.

    now, what do i include where. I think i kinda overdid it a bit by including everything everywhere, cause now i get "redefinition of class blahblah"...


  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Declarations that you want to use in different files go in headers. Definitions of functions in those headers go in their own source files. Be sure to use inclusion guards on your headers to avoid multiple inclusion:
    #ifndef SOMEHEADER
    #define SOMEHEADER
    // Stuff goes here
    Now just include the headers wherever you need them and compile the source files with the rest of your project if they aren't already object files. Then you would just link them.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Same old beginner question...
    By Sharmz in forum C Programming
    Replies: 15
    Last Post: 08-04-2008, 11:48 AM
  2. C programing doubt
    By sivasankari in forum C Programming
    Replies: 2
    Last Post: 04-29-2008, 09:19 AM
  3. beginner question
    By k1ll3r in forum C++ Programming
    Replies: 12
    Last Post: 05-21-2006, 01:40 PM
  4. MFC include BS
    By VirtualAce in forum Windows Programming
    Replies: 4
    Last Post: 10-31-2005, 12:44 PM
  5. to #include or not to #include
    By krygen in forum C++ Programming
    Replies: 9
    Last Post: 12-25-2004, 12:06 AM