I'm trying to work with classes in separate files in CodeBlocks but I'm getting the following problem.
I have 3 files: main.cpp
, clasa.h
and clasa.cpp
.
clasa.h
#pragma once
class clasa
{
public:
clasa();
};
clasa.cpp
#include "clasa.h"
#include <iostream>
using namespace std;
clasa::clasa()
{
cout<<"hi";
}
main.cpp
#include <iostream>
#include "clasa.h"
using namespace std;
int main()
{
clasa obj;
return 0;
}
When I include these 3 files into a project, the output is hi
.
When I DON'T include them into a project, main.cpp just doesn't build. But if i replace "clasa.h"
with "clasa.cpp"
it works again.
Why does it not work otherwise?