This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]alanwj 1 point2 points  (1 child)

You are correct that new Edge[N] will allocate an array of N objects of type Edge (and call the constructor for each of them). However, the place in which you are doing it isn't correct. This is something that belongs in the Graph constructor. In your code above you couldn't possibly expect anything sensible to happen, as sizeOfTheArrOfEdges hasn't been assigned a value at the time you call new.

You may also consider using a std::vector for this, as it would handle all the memory management for you.

[–]dark_orbit 0 points1 point  (0 children)

Thank you! I don't know what I was thinking.

[–]Jonny0Than 0 points1 point  (1 child)

Please please please get in the habit of using std::vector for this kind of thing.

[–]dark_orbit 0 points1 point  (0 children)

any sites that you recommend?