0

I have the following question.

Check the below block of code, it initializes my members of my structure correctly.

typedef struct
{
    int var00;
    int var01;
}struct_;

int main()
{


    struct_ my_struct;
    memset(&my_struct,'\0',sizeof(struct_));
    return 0;
}

My new structure now(see below), includes also an std::list. What I have to do now, to keep the memset command in the code?

typedef struct
{
    int var00;
    int var01;
    std::list<int> my_list
}struct_list_included;

int main()
{


    struct_list_included my_struct;
    memset(&my_struct,'\0',sizeof(struct_list_included));
    return 0;
}
gsamaras
  • 71,951
  • 46
  • 188
  • 305
KostasA
  • 5,204
  • 6
  • 23
  • 29
  • 1
    Why not simply provide a constructor? Also, those typedefs are not needed in C++. –  Oct 16 '18 at 15:08
  • If you are coming from a C background and are learning C++ I suggest you get yourself a [good C++ book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). Your code has a lot of C-ism's in it that are unnecessary as C++ has built in mechanics to do these things. – NathanOliver Oct 16 '18 at 15:15

1 Answers1

1

std::list is not a POD type, so I don't think you can do this via memset().

gsamaras
  • 71,951
  • 46
  • 188
  • 305