I have a problem with this program or, better said... with this idle, which is not compiling correctly when running the program. I had run it in others compilers, like Repl. It and it works perfectly.
File: main.cpp
#include <fstream>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
using namespace std;
#include <iostream>
#include "Dumbbell.hpp"
//
int main(){
Dumbbell d1,d2;
double val1, val2;
cout << "Enter two values, please: " << endl;
cin >> val1 >> val2;
d1.setWeight(val1);
d2.setWeight(val2);
cout << "Dumbbell #1: " << d1.getWeight() << " lbs" << endl;
cout << "Dumbbell #2: " << d2.getWeight() << " lbs" << endl;
return 0;
}
File: Dumbbell.hpp
#include <iostream>
using namespace std;
#ifndef _Dumbbell_H_
#define _Dumbbell_H_
class Dumbbell {
private:
double weight;
public:
Dumbbell ();
Dumbbell (float w);
double getWeight ();
void setWeight (double w);
~Dumbbell ();
};
#endif //_Dumbbell_H_
File: Dumbbell.cpp
#include "Dumbbell.hpp"
Dumbbell::Dumbbell () { // Default Constructor
weight = -1;
}
Dumbbell::Dumbbell (float w) { // Non-Default Constructor
weight = w;
}
Dumbbell::~Dumbbell() {
cout << "From the Destructor!" << endl;
}
void Dumbbell::setWeight(double w) {
this -> weight = w;
}
double Dumbbell::getWeight() {
return weight;
}
But in VS Code, it shows me a message when I execute main...
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\giuma\AppData\Local\Temp\ccPFLsZY.o:main.cpp:(.text+0x1d): undefined reference to `Dumbbell::Dumbbell()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\giuma\AppData\Local\Temp\ccPFLsZY.o:main.cpp:(.text+0x27): undefined reference to `Dumbbell::Dumbbell()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\giuma\AppData\Local\Temp\ccPFLsZY.o:main.cpp:(.text+0x81): undefined reference to `Dumbbell::setWeight(double)'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\giuma\AppData\Local\Temp\ccPFLsZY.o:main.cpp:(.text+0x94): undefined reference to `Dumbbell::setWeight(double)'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\giuma\AppData\Local\Temp\ccPFLsZY.o:main.cpp:(.text+0xb7): undefined reference to `Dumbbell::getWeight()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\giuma\AppData\Local\Temp\ccPFLsZY.o:main.cpp:(.text+0x105): undefined reference to `Dumbbell::getWeight()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\giuma\AppData\Local\Temp\ccPFLsZY.o:main.cpp:(.text+0x142): undefined reference to `Dumbbell::~Dumbbell()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\giuma\AppData\Local\Temp\ccPFLsZY.o:main.cpp:(.text+0x14c): undefined reference to `Dumbbell::~Dumbbell()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\giuma\AppData\Local\Temp\ccPFLsZY.o:main.cpp:(.text+0x15c): undefined reference to `Dumbbell::~Dumbbell()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\giuma\AppData\Local\Temp\ccPFLsZY.o:main.cpp:(.text+0x16a): undefined reference to `Dumbbell::~Dumbbell()'
collect2.exe: error: ld returned 1 exit status