Calling a struct constructor in a class constructor body

  • Thread starter Thread starter Karl M
  • Start date Start date
K

Karl M

Hi C++ experts!

Definitely I skipped C/C++ 101 because I have this pitfall:

I need to call the struct ctor in the class default ctor body see below:

//Some.h

struct MyStruct

{

int a[5];
 
Karl said:
Hi C++ experts!

Definitely I skipped C/C++ 101 because I have this pitfall:

I need to call the struct ctor in the class default ctor body see
below:

Add an explicitly defined default constructor to your struct that does the
initialization:

#include said:
struct MyStruct

{
int a[5];
MyStruct()
{
std::fill(a,a+sizeof(a),0);
}
};

HTH

-cd
 
Back
Top