我正在尝试将数据读入人和汽车对象,以便可以将该数据存储到数组中。
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Person
{
public:
Person(string name, int age) { cout << "\n\tBuilding a Person";} //constructor
~Person() { cout << "destructing Person";} //destructor
//accessor methods
string GetName () {return name;}
int GetAge () {return age;}
private:
string name;
int age;
};
Person::Person (string pname, int page)
{
name = pname;
age = page;
}
class Car
{
public:
Car(string model, Person* owner, Person* driver) { cout<< "building a car";}
~Car() { cout << "destructing a car";}
//accessor methods
string GetModel () {return model;}
Person* GetOwner () {return owner;}
Person* GetDriver() {return driver;}
private:
string model;
Person* owner; // pointer to owner which is an object of class person.
Person* driver; // pointer to driver which is an object of class person.
};
Car::Car (string Carmodel, Person* Carowner, Person* Cardriver) // car object to hold car model, carowner, and car driver.
{
model = Carmodel;
owner = Carowner;
driver = Cardriver;
}
int main()
{
vector<Car*> dealership; //vector pointer of car objects.
vector<Person*> people; //vector pointer of person objects.
string n;
int a;
Person* user = new Person(n, a);
当我尝试将数据读入以下变量时,我收到一个错误,没有运算符匹配这些操作数。如何让用户输入上述人员对象?
cin << n;
cin << a;
Car* vehicle;
cout << "please enter the name of a person and a car model" << '\n';
return 0;
}