comma at the beginning of a command

Hello all,

I have found a piece of code, where there is a comma right befores the name of the class members, and no semicolons at the end. What does this comma mean? Where can I find reference about it? Thanx in advance!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
	Particle(T oPosition, float nMass, float nDrag = 0.96)
		:position(oPosition)
		,mass(nMass)
		,drag(nDrag)
	{
		if(mass == 0.0) {
			inverse_mass = 0;
		}
		else {
			if(mass < 0.001) {
				mass = 0.001;
			}
			inverse_mass = 1/mass;
		}
	}
This is just a spacing issue. You have to keep in mind that for the most part, and with the exception of preprocessor commands, C++ doesn't care about whitespaces. So the above code is the same as:

1
2
3
4
5
6
7
8
9
10
11
12
	Particle(T oPosition, float nMass, float nDrag = 0.96) :position(oPosition) ,mass(nMass) ,drag(nDrag)
	{
		if(mass == 0.0) {
			inverse_mass = 0;
		}
		else {
			if(mass < 0.001) {
				mass = 0.001;
			}
			inverse_mass = 1/mass;
		}
	}

Some people find one easier to read, others see it the other way around.
Last edited on
I personally prefer writing the commas before the line break, cause it's closer to how you normally read text.

For example
, no one writes like this.
Topic archived. No new replies allowed.