class game_list
{
public:
string name;
};
game_list *pointer;
int main()
{
vector<game_list*> mainVector;
pointer=new game_list;
cin>>pointer->name;
mainVector.push_back(pointer);
cout << "Hello world!" << endl;
cout << mainVector[1];
return 0;
}
game_list
是类声明。vector<game_list*>
是包含一堆game_list
类指针的向量。我正在尝试打印game_list
向量内每个的属性。到目前为止我已经尝试过,mainVector[1].name
但似乎它不起作用。有什么建议吗?