> What is the problem in line 19?
> I'm releasing the memory after assigning the adjncy to adjncy_.
a pointer holds a value, that value is a memory address
say that you do
int *a = new int[100];
, then check the value of `a' and has 0xfece5
starting there are 100 integers that you may use.
then you do
b = a;
now both `a' and `b' contain 0xfece5, and you may access those 100 integers using any of them
you release the memory with
delete []a;
, now 0xfece5 is no longer available for you, 0xfece5 is no longer valid
`b' still points there so it becomes an invalid pointer, so when you try to access your 100 integers with `b' you incur in undefined behaviour.
basically, then burned your house and you're trying to go to the bathroom upstairs.
> I need to do something like third option.
then you may use vector::data() (note that the vector should not be destroyed or the pointer will become invalid)
perhaps the last example wasn't good
1 2 3 4 5
|
int a;
int b;
int c;
int* ptr[] = {&a, &b, &c};
*ptr[1] = 42; //modifies the content of `1'
|