0

I am dealing with a struct mf fixed arrays of char, but the size and placement of some of these members depend on other members. so I want to use __declspec(property) to dynamically retrieve these 'variable' members

so Ideally it would look something like this:

struct tVariableRecord
{
    char cRecordType;
    union
    {
        struct
        {
            char cRecordType1_Field1[4];
            char cRecordType1_Filler[6];
            char cRecordType1_Field2[6];
            char cCRLF[2];
        };
        struct
        {
            char cRecordType2_Field1[6];
            char cRecordType2_Field2[6];
            char cCRLF[2];
        };
    }
    __declspec(property(get=get_Field2))   char cField2[6];
    char [6]&get_Field2()
    {
        static char cBadField2[6] = { '#', '#', '#', '#', '#', '#' };
        switch (cRecordType)
        {
            case '1':
                return cRecordType1_Field2;
                break;
            case '2':
                return cRecordType2_Field2;
                break;
            default:
               throw(unknownRecordType);
               return cBadField2;
               break;
         }
    }
};

I know the above won't work, but is there a way to do the same thing?

dmjalund
  • 285
  • 2
  • 9
  • Well.. this is new to me.. I never knew such a thing exists :S.. I think the return type for `get_Field2` is wrong. It might have to be `char*`. That function signature doesn't compile for me in gcc/g++. – Brandon Aug 08 '14 at 03:31
  • 1
    Don't know if it's going to work with `__declspec(property)`, but the correct way to declare a function that returns a reference to an array is like this: `char (&get_Field2())[6] {...}` – Igor Tandetnik Aug 08 '14 at 04:55
  • Igor Tandetnik what versions of c++ does this work for? – dmjalund Aug 08 '14 at 06:44

0 Answers0