Calling a struct constructor in a class constructor body

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];
 
C

Carl Daniel [VC++ MVP]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top