tags:

views:

80

answers:

4

What does line 6 means? I am not understanding what is that, please can anyone elaborate on this?

class A
{
  int sz;
  double *dptr;
public:
  A(int size) : sz(size) {dptr= new double[size];} // line 6
  ~A();           // line 7
};
A::~A()           // line 9
{
  delete dptr[];  // line 11
}
+4  A: 
A(int size) // a constructor with a size argument
: sz(size) // initialize the sz member to the given size
{
    dptr = new double[size]; // allocate an array of doubles with the given size
}
jtbandes
+1, beat me to it.
David
A: 

It means that the instance variable sz will automatically be initialised to the value of the size parameter given to the constructor.

David
A: 

Got the answer. Its like line 6 is a constructor call in which variable sz will be initialzed with the input parameters i.e. "size".

chitresh
+1  A: 

You have a problm in your destructor - it should read:

A::~A()           // line 9

{

  delete [] dptr;  // line 11

}

But there is no other error in your code.

anon