Vector Initialisation in C++

自闭症网瘾萝莉.ら 提交于 2019-12-02 04:38:45

Your Node class has a pointer member of type CombinedFragment* called cfrag. This creates dangling references if you don't defined your own copy ctor and assignment operators. Further, a proper dtor is required to prevent leaks if Node is responsible for allocating/deallocating cfrag. If you don't want to deep-copy CombinedFragment you can use a shared_ptr.

Also, the default ctor for Node probably doesn't even need to be there (it leaves cfrag to an uninitialized state).

I can see one problem; when you declare 1000 vector objects and then do a push_back you're adding to the end of the vector, i.e. the objects that you're trying to add are at 1001, 1002.... etc. If declaring 1000 vector objects doesn't give you a runtime error, I would first see what's the default definition (since the first 1000 node objects have default values), since that's not error out and compare against the actual data I'm trying to load. Hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!