求帮忙啊~各位大侠
我定义了一个选票类,成员变量string names[12],想用来存放每张选票上所选的候选人名单,可是编译总是出现错误啊~我是个菜鸟,求帮忙啊~~~~strcpy函数有什么特别的要求吗,我能两个变量都是地址吗???#include <iostream>
#include "string.h"
//using namespace std;
class Ticket{
private:
string names[12];//被投票的候选人名字列表
int nameNum;//每张选票上的名字个数
public:
Ticket();//构造函数
Ticket(string names[12],int num);
~Ticket();//析构函数
string getName(int i);//获取本张选票的第i个名字
void setName(string name,int i);//设置第i个候选人姓名
int getNameNum();//获得所选人数个数
void setNameNum(int num);//设置所选人数个数
};
Ticket::Ticket(){
for(int i=0;i<12;i++){
this->names[i]=" ";
//strcpy(names[i]," ");
}
this->nameNum=0;
}
Ticket::Ticket(string names[],int num){
// strcpy(this->names,names[0]);
this->names=names;
this->nameNum=num;
}
Ticket::~Ticket(){
}
string Ticket::getName(int num){
return this->names[num];
}
void Ticket::setName(string name,int i){
this->names[i]=name;
}
int Ticket::getNameNum(){
return this->nameNum;
}
void Ticket::setNameNum(int num){
this->nameNum=num;
}
d:\program files\microsoft visual studio\myprojects\work5_vote\ticket.h(28) : error C2440: '=' : cannot convert from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > []' to 'class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > [12]'
There are no conversions to array types, although there are conversions to references or pointers to arrays