sorry I am a beginner and I am trying to run this code from this video here: https://www.youtube.com/watch?v=gq2Igdc-OSI&ab_channel=thenewboston
Here is my code:
main.cpp
#include <iostream>
#include "Mother.h"
#include "Daughter.h"
using namespace std;
int main() {
Mother mom;
mom.sayName();
}
Mother.h
#ifndef MOTHER_H
#define MOTHER_H
class Mother
{
public:
Mother();
void sayName();
};
#endif
Mother.cpp
#include <iostream>
#include "Mother.h"
#include "Daughter.h"
using namespace std;
Mother::Mother()
{
}
void Mother::sayName() {
cout << "I am a Roberts!" << endl;
}
Daughter.h
#ifndef DAUGHTER_H
#define DAUGHTER_H
class Daughter
{
public:
Daughter();
};
#endif
Daughter.cpp
#include <iostream>
#include "Mother.h"
#include "Daughter.h"
using namespace std;
Daughter::Daughter()
{
}
My error is: "undefined reference to `Mother::sayName()' collect2.exe: error: ld returned 1 exit status" What am I doing wrong? It's the exact same as the video, am I missing something? They are all in the same folder. I'm using VS Code.
here is my tasks.json file, what should i change?
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\Users\\Taro\\Desktop\\MinGW\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${workspaceFolder}\\*.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: C:\\Users\\Taro\\Desktop\\MinGW\\bin\\g++.exe"
}
]
}
here is the error message in the terminal:
PS C:\Users\Taro\Desktop\CIS 250> cd "c:\Users\Taro\Desktop\CIS 250\" ; if ($?) { g++ main.cpp -o main } ; if ($?) { .\main }
c:/users/taro/desktop/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Taro\AppData\Local\Temp\ccBwABJt.o:main.cpp:(.text+0x15): undefined reference to `Mother::Mother()'
c:/users/taro/desktop/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Taro\AppData\Local\Temp\ccBwABJt.o:main.cpp:(.text+0x21): undefined reference to `Mother::sayName()'
collect2.exe: error: ld returned 1 exit status