Question

i.m using vc6, i made a struct like this:

struct FileInfo
{
    char   filename[200] = {0};
    char   ext[20] = {0};
    int    f_size=0;
    int    offset=0;
    char*  pData=0;
};

but I got a error C2059: syntax error : '{' error, and i dont know how to initialize arrays inside correctly.

Was it helpful?

Solution

You initialize the members when you create an instance of this structure. In C++ this is done in the constructor while in C it's done like:

struct FileInfo my_file_info = { { 0 }, { 0 }, 0, 0, 0 };

The C way can of course be used in C++ too, if you don't want to add a constructor (for example if the structure is shared between a C and a C++ program).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top