jeudi 5 décembre 2019

If statement inside Struct Declaration C++

I have a doubt regarding structs and if statements in C++

For the sake of simplicity, I have created a sample code to explain my intention

int var = 10

struct example{
    int a;
    int b;
    if(var > 8){
        int c;
    }
};

I have a codebase which uses similar kind of code as above. Commenting out the if portion does not give any errors. My question is

  • Could if statements be put in struct declarations?
  • If not, what is the possible remedy for this, since if statment is mandatory.

Note: I cannot use #if,#else directives to mitigate this, so please help me find another solution.

Aucun commentaire:

Enregistrer un commentaire