c++structconstructor

Deprecated struct constructor syntax


I am migrating an old C++ Library with much of the code > 20 years old. I came upon a struct declaration with what I think is intended to be a constructor that looks this :

struct PROPERTIES_PRESENT2
{
    bool PropertyPresence[13];

    struct PROPERTIES_PRESENT2(void)
    {
        memset((&PropertyPresence), 0, (sizeof(bool) * 13));
    }
};

This is not compiling today with modern compilers. I think I can make it work by removing the 'struct' before the constructor. But what I'm hoping for help on is : did older standards of C++ require the 'struct' before the constructor as seen above? And can anyone confirm the behaviour really would have been that of a constructor and not some long forgotten thing with side effects I should be aware of?

My 'converted' version :

struct PROPERTIES_PRESENT
{
    bool PropertyPresence[13];
    
    PROPERTIES_PRESENT(void)
    {
        memset((&PropertyPresence), 0, (sizeof(bool) * 13));
    }      
};

Solution

  • Modern version, if you identified language correctly, would be:

    struct PROPERTIES_PRESENT
    {
        bool PropertyPresence[13] = {};    
    };
    

    EDIT: Out of modern compilers, Visual Studio, even latest v.19 accepts this (https://godbolt.org/z/Ts461qM74). This is their style from early times, around VisualStudio 1.0 - 2.0.