Question about complex constructor calls

I was playing around with some code, and a question occurred to me when I was making a constructor; I know you can call to a data member in this manner:

ExampleClassConstructor(arg1):classvar(arg1)}

But I'm curious to know if you can make the bit after the ':' more complex, such as:

1
2
3
4
5
6
7
8
9
ExampleClassConstructor(arg1)
:classvar(if(arg1 > 3)
             {
               7
             }
             else
             {
               8
             })


It seems like a useful thing to be able to do. I'm not very experienced with constructors, so there may also be a blatantly obvious way to do this that is much simpler.
You could use the ternary operator.
1
2
3
4
ExampleClassConstructor(int arg1)
:	classvar(arg1 > 3 ? 7 : 8)
{
}
Last edited on
That's just the kind of thing I was hoping was possible, and less clunky than what I was thinking. Thanks!
Topic archived. No new replies allowed.