【发布时间】:2020-07-15 12:33:17
【问题描述】:
#include <iostream>
#include <cstring>
using namespace std;
class Film {
private:
string name;
int year_prod;
string producer;
string main_actor;
public:
Film();
void print()
{
cout << "\nThe name of movie: " << name;
cout << "\nThe year of produced: " << year_prod;
cout << "\nProducer: " << producer;
cout << "\nMain actor: " << main_actor << endl;
}
void SetName(string xName)
{
name = xName;
}
string GetName()
{
return name;
}
void SetYearP(int xYearP)
{
year_prod = xYearP;
}
int GetYearP()
{
return year_prod;
}
void SetProducer(string xProducer)
{
producer = xProducer;
}
string GetProducer()
{
return producer;
}
void SetMaina(string xMaina)
{
main_actor = xMaina;
}
string GetMaina()
{
return main_actor;
}
};
int main()
{
Film obs[100]; // maximum of 100 hundred films
int n;
cout << "how many films ";
cin >> n;
for (int i = 0; i < n; ++i)
{
string name;
int year;
string prod;
string actor;
cout << "enter the film name ";
cin >> name;
cout << "enter the production year ";
cin >> year;
cout << "enter the producer name ";
cin >> prod;
cout << "enter the actor name ";
cin >> actor;
obs[i].SetName(name);
obs[i].SetYearP(year);
obs[i].SetProducer(prod);
obs[i].SetMaina(actor);
}
}
我已经完成了一半的代码,但在编译时出现错误提示:函数 _main AND 1 中引用的未解析的外部符号“public: __thiscall Film::Film(void)”(??0Film@@QAE@XZ)未解决的外部。我不确定我是否以正确的方式从用户输入中获得了 n Film 的对象,因为我仍然是 OOP 的初学者。
【问题讨论】:
-
一点也不 :) @UlrichEckhardt
-
Film类没有构造函数。
标签: c++ function class oop constructor