I have a struct which is as follows:
struct octNode{
octNode* parent;
octNode* child[8];
std::vector<int> pointIndex;
//constructor of the struct
octNode()
{
memset(parent,0,sizeof(parent));
memset(child,0,sizeof(child));
}
};
But this throws a run-time error: 0xC0000005: Access violation writing location 0xcdcdcdcd. Unhandled exception at 0x771115de in Octree_octnode_0113.exe: 0xC0000005: Access violation writing location 0xcdcdcdcd.
The access violation occurs in the creation of the empty vector. Is there a way to initialize the vector in the constructor so that the error doesnt occur?
In the following
memset(parent,0,sizeof(parent));
you are passing an uninitialized pointer to memset(). Did you mean to say:
memset(&parent, 0, sizeof(parent));
or, quite simply
parent = NULL; // or nullptr
?
This line causes the use of an uninitialized pointer:
memset(parent,0,sizeof(parent));
You should just set it to NULL instead:
parent = NULL;
(Or better yet, do so in the initialization list:)
octNode() : parent(NULL)
{
memset(child,0,sizeof(child));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With