C++ and C# / Java are not the same language, though they share many similarities.
If C# and Java you specify the access modifier with the function definition:
public void foo() { ...}
public void bar() { ...}
private void foobar() {...}
In C++ it's different, the access modifier affects a block of code:
public:
void foo() { ...}
void bar() { ...}
private:
void foobar() {...}
And that's a pretty bad practice you have going on there: a ToString implementation shouldn't affect anything outside the function - known as a side effect - as it's not at all obvious that it will happen, and ToString can be called implicitly as well as explicitly so you might not be aware that the side effect is happening at all.
So wherever you got that code from, it's probably not a good example at all ...