I want to split my code into .cpp and .h files but I've never done it with classes. When compiling I get the following errors:
unresolved external symbol "public: void __thiscall Worker::show(void)" (?show@Worker@@QAEXXZ) referenced in function _main
unresolved external symbol "public: void __thiscall Worker::Worker(void)" (?show@Worker@@QAEXXZ) referenced in function _main
here's my code:
f.h
#pragma once
#include "stdafx.h"
#include<vector>
#include<iostream>
using namespace std;
class Worker
{
public:
void show();
Worker();
int i;
};
f.cpp
#include "stdafx.h"
#include<vector>
#include<iostream>
#include "f.h"
using namespace std;
void Worker::show() {
cout << i;
}
Worker::Worker()
{
int i = 0;
}
main.cpp
#include "stdafx.h"
#include<iostream>
#include "f.h"
using namespace std;
int main()
{
Worker w;
w.i = 5;
w.show();
return 0;
}
What am I doing wrong?