I'm new to cpp and learning oop. While working with headers and classes, I'm trying to define the function speak() in one file {Cat.cpp} and use headers {Classes.cpp} to use it in another file. {Cat.h}. I've did all the coding right but still error message pops up.
C:\Users\DELL\AppData\Local\Temp\cc0QWD1m.o:Classes.cpp:(.text+0xc): undefined reference to `speak()' collect2.exe: error: ld returned 1 exit status
These are the respective files:-
Cat.cpp
#include <iostream>
#include "Cat.h"
using namespace std;
void speak() {
cout << "Sound" << endl;
}
Classes.cpp
#include <iostream>
#include "Cat.h"
using namespace std;
int main()
{
speak();
return 0;
}
Cat.h
#ifndef CAT_H_
#define CAT_H_
void speak();
#endif
The tutorial guy seems to do the same thing and gets it write, does it have something to do with the IDE, he is using eclipse.
I'm Using - VSCode as IDE & G++ Compiler.
Where am I going wrong?