really dumb beginner question on include

This is a discussion on really dumb beginner question on include within the C++ Programming forums, part of the General Programming Boards category; ok, i got this: a cpp file declaring a class, with it's header file containing function prototypes. another cpp file ...

  1. #1
    rox
    rox is offline
    Registered User
    Join Date
    Nov 2003
    Posts
    34

    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"...

    Thanks.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    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:
    Code:
    #ifndef SOMEHEADER
    #define SOMEHEADER
    
    // Stuff goes here
    
    #endif
    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, 11:44 AM
  5. to #include or not to #include
    By krygen in forum C++ Programming
    Replies: 9
    Last Post: 12-24-2004, 11:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21