64,648
社区成员
发帖
与我相关
我的任务
分享
#include <vector>
class CRect {
public:
CRect();
CRect(int _x, int _y):x(_x), y(_y) {}
int x;
int y;
};
std::vector<CRect *>* vsVector;
int main()
{
vsVector = new std::vector<CRect*>;
vsVector->push_back(new CRect(1, 3));
vsVector[0]->x = 6;// Error!!! WHY???
delete vsVector;
return 0;
}
#include <vector>
class CRect {
public:
CRect();
CRect(int _x, int _y):x(_x), y(_y) {}
int x;
int y;
};
std::vector<CRect *>* vsVector;
int main()
{
vsVector = new std::vector<CRect*>;
vsVector->push_back(new CRect(1, 3));
(*vsVector)[0]->x = 6;// 只有vector对象才能这样用呀!!!!
delete vsVector;
return 0;
}
#include <vector>
class CRect {
public:
CRect();
CRect(int _x, int _y):x(_x), y(_y) {}
int x;
int y;
};
std::vector<CRect *>* vsVector;
int main(int argc, char* argv[]) {
vsVector = new std::vector<CRect*>;
vsVector->push_back(new CRect(1, 3));
(*vsVector)[0]->x = 6;// Error!!! WHY???
delete vsVector;
}
另,友情提示:这种代码是在玩儿火,工程中不能使用。