Select from two overloaded methods

102 Views Asked by At

There is a class with two similar constructors...

class CX
{
public:
    CX(HEADER header,
              __int64    i64Id); 

    CX(HEADER  header,
              const char* pszName);
    // other methods...
};

I want to call the second constructor with null pointer.

CX *data1 = new CX(&header, NULL); 
//it is ambiguous call to overloaded function

CX *data2 = new CX(&header, (const char*)NULL); 
// is correct, but against our coding standards...

CX *data3 = new CX(&header, static_cast<const char*>(NULL));
// is correct, but agains our coding standards...

const char* pszName = NULL;
CX *data4 = new CX(&header, pszName);
// this is correct but waste of stack.

Is there any better way how to select the constructor?
(nullptr would be the solution in this case, but it's not possible because it should be compilable in VC6)

1

There are 1 best solutions below

2
On

you can modify 2nd constructor taking NULL as default argument and call it passing first argument as only argument

CX(HEADER header, const char* pszName=NULL);