高手请看
请看下面这个程序:
struct Point{
int x_axis,y_axis;
vector<int> slope;
void set_value(int x,int y) { x_axis = x; y_axis = y;}
}
int main(){
vector< Point> point_set;
int x,y,i(0);
cin >> x >> y;
point_set[i++].set_value(x,y);
}
程序在vc++6.0(windows xp professional)下能够编译通过,可是在运行是会出错。具体错误为:我在输入如12 23的坐标后,enter回车,系统会跳出xp的那个
“经典”错误:1165.exe has encountered a problem and needs to close. We are sorry for the inconvenience. If you were in the middle of something ,the information you were working on might be lost....
其中1165为我这个程序的名字。
我曾试着在struct Point 中放入一个constructor: Point(int x, int y) :
x_axis = x, y_axis = y{}
然后在main中这样:
int main(){
vector< Point> point_set;
int x,y,i(0);
cin >> x >> y;
Point new_node = new Point(x,y);
point_set[i++].push_back(new_node);
}
这样更改后编译时期就会报错。
请问如何在一个vector<somekind_class > T 中添加一个somekind_class 的对象?
此外,vector中的somekind_class中是否允许有vector定义呢,如上例子中的vector<int> slope;
先行谢过!