【发布时间】:2012-12-14 20:26:40
【问题描述】:
我只是 C++ 的初学者,我正在尝试让一些向量适用于我的程序,因为我正在尝试编写一个允许用户从文件中添加/编辑/删除以前条目的程序。问题是我无法让我的设置器与向量一起正常工作。我不确定我到底做错了什么。
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
class DVD
{
public:
//Default constructor
DVD();
//Class members
vector<string> name[5];
vector<string> length[5];
vector<string> actora[5];
vector<string> actorb[5];
vector<string> year[5];
//Function to set and get DVD Name
void setDVDname(vector<string> name)
{
DVDname[5]=name[5];
}
vector<string> getDVDname()
{
return DVDname;
}
//Function to set and get DVD length
void setDVDlength(vector<string> length)
{
DVDlength=length;
}
vector<string> getDVDlength()
{
return DVDlength;
}
//Function to get and get DVD year
void setDVDyear(vector<string> year)
{
DVDyear=year;
}
vector<string> getDVDyear()
{
return DVDyear;
}
//Function to get and set DVD Actor Alpha
void setDVDactorA(vector<string> actora)
{
DVDactorA=actora;
}
vector<string> getDVDactorA()
{
return DVDactorA;
}
//Function to get and set DVD Actor Bravo
void setDVDactorB(vector<string> actorb)
{
DVDactorB=actorb;
}
vector<string> getDVDactorB()
{
return DVDactorB;
}
protected:
private:
//Variables to hold DVD information
vector<string> DVDname[5];
vector<string> DVDlength[5];
vector<string> DVDactorA[5];
vector<string> DVDactorB[5];
vector<string> DVDyear[5];
};
【问题讨论】:
-
您真的希望您的成员变量成为字符串向量数组吗?
-
很明显,您对某事感到非常困惑,并且可能对许多事情感到困惑。您是否会考虑购买一本关于该主题的书,并在您不那么困惑时再次尝试这个项目?