View Single Post
Old 07-02-2005, 01:23 PM   #1 (permalink)
fp_unit
mike
 
Join Date: Jan 2005
Location: Ottawa, ON
Posts: 79
fp_unit is on a distinguished road
Default Constructors

Is a default constructor a constructor that never takes a value, or is there a difference between a constructor that accepts no parameters and a default constructor? If you create a constructor that takes no parameters, does this automatically become your default constructor?

For instance, is this constructor a default constructor? Why or why not?

Code:
template <class T>
class ListNode
{
public:
    ListNode();
    // ...

private:
    ListNode* nextPtr;
    T* data;
};

template <class T>
ListNode<T>::ListNode():
nextPtr(0), data(0)
{}
One last question, if you provide default paramaters to a no-argument constructor, is it still a default constructor?

Code:
const int DEFAULT_ARRAY_SIZE = 10;

class Array
{
public:
    Array(arraySize = DEFAULT_ARRAY_SIZE);
    // ...

private:
    // ...
    int arraySize;
};
fp_unit is offline   Reply With Quote