The struct is defined like this:
struct Edge {
int weight;
Vertex* v1;
Vertex* v2;
};
I need to do something like
new Edges(v1, v2, v3);
but that could only be done with a “class” and using ctor. How can I create a new element of struct and initialize it at the same time?
Thanks!
You can write a constructor for a
structas well in C++. A Cstructis very limited, but in C++ there exists only 2 differences betweenstructandclass.classall members are by defaultprivate, instructall members are by defaultpublic.structdefaults topublicwhileclassdefaults toprivateThanks @gil_bz and @icepack