#include .h or .cpp file?
<p>So I have this weird looking problem: my very basic program generates an error message (undefined reference to 'foo::foo(int)') when i import the .h file of a separate class. However, when I change the import file to .cpp, it all works. </p>

<p>Now, I've read a little, and seen a few video tutorials, and they all say the same: import the .h file. So why doesn't it work? </p>

<p>I use Code::Blocks, where i compile and run(no command lines), in Windows 7. I do suspect that something isn't set up quite right, however, I do want to know for sure if it is my code that fails. </p>

<p>Main.cpp:</p>

<pre><code>#include &lt;iostream&gt;
#include "Foo.h"  //This don't work. If i include Foo.cpp it does. 

using namespace std;

int main()
{
    Foo k(10);
    cout &lt;&lt; k.getInt() &lt;&lt; endl;
}
</code></pre>

<p>foo.h:</p>

<pre><code>#ifndef FOO_H
#define FOO_H

class Foo
{
    public:
        Foo(int tall);
        int getInt()const;
    protected:
    private:
        int m;
};

#endif
</code></pre>

<p>Foo.cpp:</p>

<pre><code>#include "Foo.h"

Foo::Foo(int tall)
: m(tall)
{
    //ctor
}

int Foo::getInt()const
{
    return m;
}
</code></pre>
