Thread: Quick Question

  1. #16
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    when you create functions in different files, it's a good idea to DECLARE the function prototype in a header file, and DEFINE the function in a CPP. Only include header files.

    eg:

    Code:
    main.cpp---
    #include "myheader.h"
    
    int main(void)
    {
       MyFunc();
       return(0);
    }
    
    myheader.h---
    
    #ifndef MYHEADER_H
    #define MYHEADER_H
    
    int MyFunc(void);
    
    #endif // MYHEADER_H
    
    myheader.cpp---
    
    #include "myheader.h"
    #include <iostream>
    using namespace std;
    
    int MyFunc(void)
    {
       cout << "MyFunc\n";
       return(1);
    }
    doing this will prevent you from having problems with things being defined multiple times. The only functions that you should define a body for in header files are inline functions.

    hope this helps
    U.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  2. #17
    Registered User
    Join Date
    Apr 2002
    Posts
    99

    Got it.

    Ok thanks, I'll remember that from now on.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-26-2005, 11:05 PM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM