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;
}
2
  • 1
    Why not simply provide a constructor? Also, those typedefs are not needed in C++. Commented Oct 16, 2018 at 15:08
  • If you are coming from a C background and are learning C++ I suggest you get yourself a good C++ book. Your code has a lot of C-ism's in it that are unnecessary as C++ has built in mechanics to do these things. Commented Oct 16, 2018 at 15:15

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.