开发者

Ambiguous function/constructor call in C++

开发者 https://www.devze.com 2023-01-11 01:45 出处:网络
What does line 6 means? I am not understanding what is that, please can anyone elaborate on this? class A

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

精彩评论

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