I tried to start to code in C++ after a long time.
I started a little project and got an error after little time :(
I have two classes: MyClass and OtherClass (just as an example)
My main.cpp:
#include "MyClass.h"
#include "OtherClass.h"
int main(){
OtherClass* otherClass = MyClass::doSomething();
return 0;
}
OtherClass.h:
#pragma once
class OtherClass
{
public:
OtherClass(int a, int b, int c);
~OtherClass();
private:
int a, b, c;
};
OtherClass.cpp:
#include "OtherClass.h"
OtherClass::OtherClass(int a, int b, int c)
{
this->a = a;
this->b = b;
this->c = c;
}
OtherClass::~OtherClass(){}
MyClass.h:
#pragma once
#include "OtherClass.h"
class MyClass
{
public:
static OtherClass* doSomething();
private:
MyClass();
~MyClass();
};
MyClass.cpp:
#include "MyClass.h"
MyClass::MyClass(){}
MyClass::~MyClass(){}
OtherClass* doSomething(){
return new OtherClass(0, 0, 0);
}
For me everything seems fine.
I'm used to code in C# so maybe I'm missing something important (I guess because I'm getting this error).
The error I get:
Error 1 error LNK2019: Unresolved external symbol ""public: static class OtherClass * __cdecl MyClass::doSomething(void)" (?doSomething@MyClass@@SAPAVOtherClass@@XZ)" in function "_main". D:\Projects\TestProject\main.obj TestProject
Hope you can help me :)