Hey there I am trying to learn the basics of Classes and I defined a class and tried to set some initial values for the objects. Here are my files (I tried to include the class as a header):
My Header File
#include <string>
#ifndef ROBOTS_H
#define ROBOTS_H
using namespace std;
class Robots
{
public:
Robots();
void setType(string);
string getType();
void setPrice(float);
float getPrice();
void printRobot();
private:
string robotType;
float robotPrice;
};
#endif
.cpp for the Header:
#include <iostream>
#include <string>
#include "Robots.h"
using namespace std;
Robots::Robots()
{
robotPrice = 0;
robotType = "NULL";
}
void Robots::setType(string type)
{
robotType = type;
}
void Robots::setPrice(float price)
{
robotPrice = price;
}
string Robots::getType()
{
return robotType;
}
float Robots::getPrice()
{
return robotPrice;
}
void Robots::printRobot()
{
cout << "Your Robot Information is as follows:" << endl;
cout << "Model:" << robotType << endl;
cout << "Price" << robotPrice << endl;
}
main file
#include <iostream>
#include <string>
#include "Robots.h"
using namespace std;
int main()
{
Robots Robot1;
cout << "Initial Properties of the Robot:" << endl;
Robot1.printRobot();
cout << " " << endl;
}
When I run the main I get these errors:
Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol "public: __thiscall Robots::Robots(void)" (??0Robots@@QAE@XZ) referenced in function _main testRobots C:\Users\kucar\source\repos\testRobots\testRobots.obj 1
Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol "public: void __thiscall Robots::printRobot(void)" (?printRobot@Robots@@QAEXXZ) referenced in function _main testRobots C:\Users\kucar\source\repos\testRobots\testRobots.obj 1
Severity Code Description Project File Line Suppression State Error LNK1120 2 unresolved externals testRobots C:\Users\kucar\source\repos\testRobots\Debug\testRobots.exe 1
Can someone tell me what I am doing wrong?