Struct Constructor in C++?


Question

Can a struct have a constructor in C++?

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

1
325
9/10/2014 7:36:46 AM

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.

432
9/10/2014 7:35:05 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon