I am building a parser using C++ 11/14 (Visual Studio 2015). How do I create and initialize a table within the class, and have it compute the length of the table?
I get the following errors from the compiler:
1>d:\temp\win32project1\win32project1\source1.cpp(49): warning C4200: nonstandard extension used: zero-sized array in struct/union
1> d:\temp\win32project1\win32project1\source1.cpp(49): note: This member will be ignored by a defaulted constructor or copy/move assignment operator
1>d:\temp\win32project1\win32project1\source1.cpp(49): error C2997: 'tlv::_requests': array bound cannot be deduced from an in-class initializer
1> d:\temp\win32project1\win32project1\source1.cpp(45): note: see declaration of 'tlv::_requests'
typedef enum _TLV_TYPE : UINT32
{
tlv_type_read,
tlv_type_write,
tlv_type_param,
tlv_type_status
} TLV_TYPE;
typedef struct
{
TLV_TYPE type;
UINT32 length;
} TLV_RECORD, *pTLV_RECORD;
typedef std::function <UINT32 (pTLV_RECORD Record)> pTLV_PARSER;
typedef struct
{
TLV_TYPE type;
pTLV_PARSER parse_routine;
vector <TLV_RECORD> parameters;
vector <TLV_RECORD> response;
} TABLE, *pTABLE;
class tlv
{
public:
tlv (SOCKET Socket);
~tlv ();
UINT32 start_parse (pTLV_RECORD Record);
protected:
pTLV_PARSER parse_read;
pTLV_PARSER parse_write;
const TABLE _requests [] =
{
{tlv_type_read, parse_read, {{tlv_type_param, 4}, {tlv_type_param, 0}, {tlv_type_param, 4}}, {{tlv_type_status, 4}}},
{tlv_type_write, parse_write,{{tlv_type_param, 4}}, {{tlv_type_status, 4}}},
};
}; // End of class tlv