开发者

Ambiguous function/constructor call in C++

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= 开发者_JS百科new double[size];} // line 6
  ~A();           // line 7
};
A::~A()           // line 9
{
  delete dptr[];  // line 11
}


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
}


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.


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


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".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜