File Separation

I have a problem in file separation. I'm using CodeBlocks and these are the codes for each of them for simple code that just print text out. If I include Happy.cpp instead of Happy.h in main.cpp it will work but with Happy.h included shows me this error:

undefined reference to `Happy::Happy()'

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29


//main.cpp

#include <iostream>
#include "Happy.h"

using namespace std;

int main(){
Happy h;

}

//Happy.cpp

#include <iostream>
#include "Happy.h"

using namespace std;

Happy::Happy()
{
cout << "I'm Happy";
}

-----------------

//Happy.h

#ifndef HAPPY_H
#define HAPPY_H


class Happy
{
public:
Happy();

};

#endif // HAPPY_H
How have you set up your project in Code::Blocks? It looks like you aren't linking the files together properly.
I didn't get your mean but I create 3 different file as I showed Also I tried to use CodeBlocks option to create a new class and also tried to use Add files in Project menu. Should I linked them in another way?
Topic archived. No new replies allowed.