C++ – Struct Constructor in C++


Can a struct have a constructor in C++?

I have been trying to solve this problem but I am not getting the syntax.

Best Answer

In C++ the only difference between a class and a struct is that members and base classes are private by default in classes, whereas they are public by default in structs.

So structs can have constructors, and the syntax is the same as for classes.