Inside C++ classes, access modifiers like public
and private
are written similarly to Python branches like if
, else
, and for
statements.
class Thing {
public:
int x;
private:
int y;
};
int main() {
Thing thing;
thing.x = 0; // fine because it's public
thing.y = 0; // error because it's private
return 0;
}
Even though the two languages are doing completely different things here, you would write a branch of flow in Python like how C++'s class access modifiers are written, with a colon following the branching statement, and subsequent items within that branch uniformly indented underneath:
for digit in digits:
result += pow(digit, len(digits))