往列表中push_back出现错误
wow_allpoint *point_tag = new wow_allpoint();
memset(point_tag,0x0,sizeof(wow_allpoint));
wow_alllist.push_back(point_tag);
错误提示:
error C2228: left of '.push_back' must have class/struct/union
前提:
#include <vector>
using namespace std;
struct wow_allpoint
{
wsConnection *all_ws;
xyzf *all_point;
};
vector<wow_allpoint*>wow_alllist;
请高手指点
[解决办法]
还没有定义wow_alllist
wow_alllist在哪儿定义的?
[解决办法]
可能是比较老的编译器吧。
typedef struct wow_allpoint
{
wsConnection *all_ws;
xyzf *all_point;
}wow_allpoint;
试试?
[解决办法]
我没找到那2个类型,用int代替了,在vc6上编译没问题
- C/C++ code
#include <vector> using namespace std; struct wow_allpoint { int *all_ws; int *all_point; };vector <wow_allpoint*> wow_alllist; int main(){ wow_allpoint *point_tag = new wow_allpoint(); memset(point_tag,0x0,sizeof(wow_allpoint)); wow_alllist.push_back(point_tag); return 0;}
[解决办法]
是不是
struct wow_allpoint
{
wsConnection *all_ws;
xyzf *all_point;
};
里面的all_ws 、all_point没有分配内存造成的
还有,容器中包含指针,极容易造成内存泄露, 最好自己写一个类来管理内存