+ 3

What does ":" do in c++

Saw this in my c++ book, yet its not explained there

21st Oct 2018, 9:59 PM
Innocent Culprit
Innocent Culprit - avatar
6 odpowiedzi
+ 9
I think is just Synstax. Just to make code more readeble, here look #include <iostream> using namespace std; class Box { public: double length; // Length of a box double breadth; // Breadth of a box double height; // Height of a box }; See the word special key name public: so if : in the end is more readeble for a coder to know everithyng after : is public. until end of scope
21st Oct 2018, 10:06 PM
Anya
Anya - avatar
+ 8
i’m not sure... class_derivated: class_base ? it’s analog to reservated word “extends” in java?
21st Oct 2018, 10:33 PM
AntonioJFN
AntonioJFN - avatar
+ 6
You also use it to define labels. goto error; ... error: ... You also use it do define cases in a switch statement. switch(x){ case 1: ... }
21st Oct 2018, 11:04 PM
Schindlabua
Schindlabua - avatar
+ 2
thank you for your answers, learned a lot, I posted a new question that is related to this one. Check that out if you want.
22nd Oct 2018, 8:28 AM
Innocent Culprit
Innocent Culprit - avatar
+ 1
Ternary operator also make use of colon, for separating the true and false block of code to execute. <condition> ? <true block> : <false block>
22nd Oct 2018, 1:35 AM
Ipang
+ 1
Its a way of seperating a code block. Usually curly bracket do this. But at some poits : is used. Its just syntax. its how the compiler was designed...
22nd Oct 2018, 5:59 PM
Thathsara Liyanage
Thathsara Liyanage - avatar