Question about ternary operator in initializer list
-
Hi, i have two classes, and i am trying to use the ternary operator in the initializer list to initialize Class2 memeber to some value or null based on the data in MyClass2 constructor: MyClass { ... int x; int y; } MyClass2 { ... MyClass myObj; } MyClass2 Constructor: Version 1)
MyClass2(const AnotherClass* data) :
myObj(data ? data->x : MyClass()) --compile errorVersion 2)
MyClass2(const AnotherClass* data) :
myObj(data ? data->x : MyClass my) --synatax errorI get the following error: error: no match for ternary 'operator?:' in ... How could i fix this? Thanks
-
Hi, i have two classes, and i am trying to use the ternary operator in the initializer list to initialize Class2 memeber to some value or null based on the data in MyClass2 constructor: MyClass { ... int x; int y; } MyClass2 { ... MyClass myObj; } MyClass2 Constructor: Version 1)
MyClass2(const AnotherClass* data) :
myObj(data ? data->x : MyClass()) --compile errorVersion 2)
MyClass2(const AnotherClass* data) :
myObj(data ? data->x : MyClass my) --synatax errorI get the following error: error: no match for ternary 'operator?:' in ... How could i fix this? Thanks
-
Hi, i have two classes, and i am trying to use the ternary operator in the initializer list to initialize Class2 memeber to some value or null based on the data in MyClass2 constructor: MyClass { ... int x; int y; } MyClass2 { ... MyClass myObj; } MyClass2 Constructor: Version 1)
MyClass2(const AnotherClass* data) :
myObj(data ? data->x : MyClass()) --compile errorVersion 2)
MyClass2(const AnotherClass* data) :
myObj(data ? data->x : MyClass my) --synatax errorI get the following error: error: no match for ternary 'operator?:' in ... How could i fix this? Thanks