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".
精彩评论