C++新手关于在类和结构体中使用vector容器的问题
舟遥 2011-10-14 04:22:08 类的私有成员可以定义为vector对象吗?结构体中能用vector对象吗?
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#define RANK 10
using namespace std;
class Open{
public:
Open():vec(RANK){};
Open(const vector<int>& vec,int fn):vec(RANK){
this.vec.assign(vec.begin(),vec.end());
//'vec' is not a type
//request for member of non-aggregate type before '.' token
this.fathernumber = fn;
//fathernumber' is not a type
//request for member of non-aggregate type before '=' token
};
void copy(Open& a,Open& b);
void exchange(int x,int y);
int getfathernumber();
vector<int> getvec();
private:
vector<int> vec;
int fathernumber;
};
void Open::copy(Open& b){
this.vec.assign(b.getvec().begin(),b.getvec().end());
}
void Open::exchange(int x,int y){
int temp;
temp = this.vec[x] ;
this.vec[x] = this.vec[y] ;
this.vec[y] = this.vec[x] ;
}
int Open::getfathernumber(){
return this.fathernumber;
}
vector<int> Open::getvec(){
return this.vec;
}
typedef struct Closed{
int number;
vector<int> vec(10);
int fathernumber ;
}Closed,*Closedptr;
还有还多类似的提示,不一一列举了,大概都是在vector变量处,请问是为什么啊?