I'm having trouble overoading the new operator when user arguments are present.
Here's the declaration of my overloaded operators:
1 2 3 4 5 6 7 8 9 10
class DA
{
public:
/* default operators */
void * operatornew (size_t sz);
voidoperatordelete (void *p);
/* operators taking one user parameter */
void * operatornew (size_t sz, size_t numcol);
voidoperatordelete (void *p, size_t numol);
};
Here's the invocation of the overloaded new operator:
m_da = new DA (input_cols);
If I leave out the first (default) pair of operators, I get the following compile error:
error (464) : no instance of overloaded "DA::operator new" matches these operands argument types are: (unsignedint)
If I include the first pair of operators, the code compiles, but in debugging the first new operator is called which is not what I want. I'm expecting that the second new operator should be called.
In googling overloading the new operator, it appears that the size of the object is automatically passed as the first operator and any user operators follow that. What am I missing?
new DA (input_cols) calls the single-argument operator new and uses a single-argument contructor of DA. The syntax to call the two-argument overload is new (input_cols)DA (for default-constructible DA) or new (input_cols)DA(args...) (for DA whose constructor takes args..)