Operator :
-
You cam use ":" with "?". In the following example, the "?" can be interpreted as "then" and the ":" as else.
int result = i > 10 ? 9 : 11;
This is equivalent to:if (i > 10) result = 9; else result = 11;
The ":" is also used with "public", "private" and "protected" to define security access within a class and inheritance.clas Derived : public Base { public: protected: private: };
You also use it to create a constructor initialize list in classes:class Foo { public: Foo() : value(1) {} protected: private: int value; };
George -
the operator : doesn't exist
Don't know where to start ?
Refer the Forums Guidelines and ask a friend -
the operator : doesn't exist
Don't know where to start ?
Refer the Forums Guidelines and ask a friend":" is not an operator by itself but in combination with "?" as a conditional operator "?:". -- modified at 20:54 Sunday 10th December, 2006 -- modified at 20:54 Sunday 10th December, 2006
"We make a living by what we get, we make a life by what we give." --Winston Churchill
-
":" is not an operator by itself but in combination with "?" as a conditional operator "?:". -- modified at 20:54 Sunday 10th December, 2006 -- modified at 20:54 Sunday 10th December, 2006
"We make a living by what we get, we make a life by what we give." --Winston Churchill
that's why i said that operator : doesn't exist :suss: moreover, : appears in other situations, like classes inheriting in class definitions, construction list in class constructors definitions, etc... but still this is not an operator per se.
Don't know where to start ?
Refer the Forums Guidelines and ask a friend -
that's why i said that operator : doesn't exist :suss: moreover, : appears in other situations, like classes inheriting in class definitions, construction list in class constructors definitions, etc... but still this is not an operator per se.
Don't know where to start ?
Refer the Forums Guidelines and ask a friendI never said it was an operator. I just demonstrated its usage, and you explicited stated it was not an operator and restated my previous post. Also, I believe the ":" falls under the category of punctuation. Punctuation and operators are lexemes. Nevertheless, I appreciate your comments and hope we didn't confuse anyone.
"We make a living by what we get, we make a life by what we give." --Winston Churchill