I am trying to call another function, foo(), in the Raw class from main.cpp but I keep on getting this error and I do not understand what is wrong with my code. I am working in C++, and I am using the QT framework. I am new to this language and framework.
Error:
LNK2019: unresolved external symbol “public:void __thiscall RAW::foo(void)” (?foo@Raw@@QAEXXZ) referenced in function_main. File not found:main.obj
main.cpp
#include "raw.h"
using namespace std;
int main(int, char*)
{
Raw newRaw;
newRaw.foo();
return 0;
}
raw.cpp
#include "raw.h"
#include <iostream>
using namespace std;
void foo()
{
cout << "hi\n";
}
Raw::Raw()
{
cout << "raw\n";
}
raw.h
#ifndef RAW_H
#define RAW_H
class Raw
{
public:
Raw();
void foo();
};
#endif // RAW_H
In raw.cpp you have to define foo like this:
You have to put Raw:: so that the compiler knows that this is the class member function foo and not some other independent function.