enter code here
my code is not compiling, I am using VSCode and these files, but I do not see anything wrong, the compiler literally says this
/home/cristian/Documents/PersonalCode/Cpp/Houses/main.cpp:16: undefined reference to `House::setNumStories(int)'
But, it does not make sense to me, everything seems to be right because I am calling the respective variables.
Is it possible that because I am using VSCode in ubuntu and NOT visual studio that has some kind of relationship with my problem ?
Sorry if the question is too basic, I am just getting started with C++
Thanks in advance.
Here are the files :
main.cpp
#include <iostream>
#include <string>
#include "House.h"
using namespace std;
//int printHouseData(House Info);
int main()
{
House myHouse;
House yourHouse;
myHouse.setNumStories(2);
myHouse.setNumWindows(6);
myHouse.setColor("red");
yourHouse.setNumStories(3);
yourHouse.setNumWindows(10);
yourHouse.setColor("blue");
/*printHouseData(myHouse);
printHouseData(yourHouse);*/
cout << "All is good !"<< endl;
return 0;
}
/*int printHouseData(House Info)
{
cout << "My house is "<<Info.getColor() << " and has "
<< Info.getNumStories() << " stories and "
<< Info.getNumWindows() << " windows." << endl;
return 0;
}*/
House.h
#include <string>
using namespace std;
class House {
public:
void setNumStories(int numStories);
void setNumWindows(int numWindows);
void setColor(string color);
int getNumStories() const;
int getNumWindows() const;
string getColor() const;
private:
int numStories;
int numWindows;
string color;
};
House.cpp
#include "House.h"
using namespace std;
void House::setNumStories(int numStories)
{
this -> numStories = numStories;
}
void House::setNumWindows(int numWindows)
{
this -> numWindows = numWindows;
}
void House::setColor(string color)
{
this -> color = color;
}
int House::getNumStories() const
{
return numStories;
}
int House::getNumWindows() const
{
return numWindows;
}
string House::getColor() const
{
return color;
}