The folllowing code has me boggled. Here is a sample of code where you can see that the constructor for the FeetInches class is setting the numbers equal to the private variables inside...

int main()
{
   // Define a LinkedList object.
   LinkedList<FeetInches> list;

   // Define some FeetInches objects.
   FeetInches distance1(5, 4); // 5 feet 4 inches
   FeetInches distance2(6, 8); // 6 feet 8 inches
   FeetInches distance3(8, 9); // 8 feet 9 inches

   // Store the FeetInches objects in the list.
   list.appendNode(distance1); // 5 feet 4 inches
   list.appendNode(distance2); // 6 feet 8 inches
   list.appendNode(distance3); // 8 feet 9 inches

Yet this is the constructor...

// Constructor
	FeetInches(int f = 0, int i = 0)
		{ feet = f;
		  inches = i;
		  simplify(); }

WHY in the parameter list does f= 0 and i = 0? What does it do... If you need to see the full source code ill post it. But I must have forgot something i learned...

Recommended Answers

All 2 Replies

it's called default constructor..
->WHY in the parameter list does f= 0 and i = 0?..
prevent overflow/underflow i guess..i dont know why..
->What does it do...
Like all functions, a constructor can have default arguments.
They are used to initialize member objects. If default values are
supplied, the trailing arguments can be omitted in the expression
list of the constructor. Note that if a constructor has any
arguments that do not have default values, it is not a default
constructor

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.