Overloading new operator with args

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 * operator new (size_t sz);
	void operator delete (void *p);
        /* operators taking one user parameter */
	void * operator new (size_t sz, size_t numcol);
	void operator delete (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: (unsigned int)


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..)
Topic archived. No new replies allowed.