Won't compile. (Using separate files)

I'm trying to learn how to use different files. But this doesn't work. The only message i get is:

C:\Users\SirEgo\Downloads\Game\Thecompanygame.o:Thecompanygame.cpp|| undefined reference to `Hire::Hire()'|


1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include "Hire.h"


using namespace std;

int main()
{
    Hire employee;
    return 0;
}

1
2
3
4
5
6
7
8
9
#include "Hire.h"
#include <iostream>

using namespace std;

Hire::Hire()
{
    cout << "lol" << endl;
}

1
2
3
4
5
6
7
8
9
10
11
#ifndef HIRE_H
#define HIRE_H


class Hire
{
    public:
        Hire();
};

#endif // HIRE_H 
Are you using an IDE to help link/compile your code or are you working without an IDE? If without an IDE, how are you trying to compile it? If you're using an IDE, which is it?

As an aside: try to get into the habit of only having #includes when you need them. ex: You shouldn't need #include <iostream> in your main file (or using namespace std either, there's nothing in your main function that uses std::).
Last edited on
Are you using an IDE to help link/compile your code or are you working without an IDE? If without an IDE, how are you trying to compile it? If you're using an IDE, which is it?


code blocks

As an aside: try to get into the habit of only having #includes when you need them. ex: You shouldn't need #include <iostream> in your main file (or using namespace std either, there's nothing in your main function that uses std::).

I forgot about that.

Make sure you have all files in the same project.
Topic archived. No new replies allowed.