Search code examples
c++includelnk2005

#include, error LNK2005


Alirhgt, i tried to sort this one out myslef but can't. So, i have a task to build a paint program in the console, i have a set of functions dealing with the console. My task being only to connect them logically to do something useful. The problem is that everytime i #include the two files given : the .h and the .cpp file, i get the LNK2005 error that they are already defined. If i only include the header file, the functions don't do anything( i tried using one function but the console just stood there doing nothing). Can anybody tell me what i'm doing wrong? I haven't worked with C++ in a bit, so i might be doing some stupid mistake.


Solution

  • First off, you should never include cpp files.

    Second, you might need include guards. Format headers like this:

    #ifndef FILE_H
    #define FILE_H
    
    struct foo {
        int member;
    };
    
    #endif
    

    You can read about why from here: http://en.wikipedia.org/wiki/Include_guard