Sep 032012
 

In C++, a struct can have functions also, the way we have in a class. For example, the below definition of Node in C++ is perfectly valid.

struct Node
{
  private:
    int data;
    Node *link;

  public:
    // Default Constructor
    Node():data(0), link(NULL)
    {
        cout<< " Default Constructor";
    }

    // Single Argument Constructor
    Node(int d):data(d), link(NULL)
    {
        cout<< " Single Argument Constructor";
    }
};

What is the difference between the two ?
Continue reading »