I'm new to writing classes.
This is the class file.
Code:
#include <iostream>
#include <string>
using namespace std;
class phones
{
private:
string phone;
string cost;
int year;
public:
phones();
void setPhone (string p );
string getPhone();
void setCost (string c );
string getCost();
void setYear (int y );
int getYear();
void Displayinfo();
#include <"phones.h">
#include <iostream>
#include <string>
phones::phones(){}
void phones::setPhone (string p )
{
phone=p;
}
string phones:: getphone()
{
return phone};
void phones::setCost (string c )
{
cost=c;
}
string phones:: getcost()
{
return cost};
void phones::setYear (int y )
{
year=y;
}
intphones:: getyear()
};
and this is the main cpp file.
Code:
//#include <iostream>
//#include <"phones.h">
#include <string>
using namespace std;
int main()
{
string phone;
string cost;
int year;
phones object; //error here
object.setphone("samsung");
object.setcost("thousand");
object.setyear("2010");
return 0;
}
The error in the main file states that the object (phones object) is undeclared.