Originally Posted by
franziss
Below is a constructor for a class Transaction. What does : length(l) represents?
Code:
Transaction(int l) : length(l) {t = new int[l];}
That above would be the same as putting:
Code:
Transaction(int l) {
t = new int[l];
length = l;
}
Its obvious that on constructing a class that you will want some initial value for the variables in that class, so you can use : as it does, then one of the classes values, then the value you want in brackets, in this case its a value passed in through the parameter. Another case you might set say xPosition(0) and yPosition(0). It saves space, its more clear, and I forget but it may be quicker (not sure).