2

I have the below class in header file

class CodeListSqlGenerator : public ICodeListSqlGenerator,public CDialog


{
    ........
public:
CodeListSqlGenerator(IIntelligentCodeListUpgraderParameter *i_intelligent_codelist_upgrader_parameter);
}

When I use a new operator in .cpp file to create an object of type CodeListSqlGenerator

ICodeListSqlGenerator *CreateCodeListSqlGeneratorInterface(IIntelligentCodeListUpgraderParameter *i_intelligent_codelist_upgrader_parameter)
{
ICodeListSqlGenerator *i_codelist_sql_generator = new CodeListSqlGenerator(i_intelligent_codelist_upgrader_parameter);
return i_codelist_sql_generator;
}

I'm get getting the below when compiled error C2661: 'CObject::operator new' : no overloaded function takes 4 arguments How do I rectify this error? Thanks in advance -Athreya

Xeo
  • 129,499
  • 52
  • 291
  • 397
Greenhorn
  • 658
  • 2
  • 8
  • 24
  • What do the constructor definitions in the class hierarchy look like? This error can be caused by an incorrect base initialization in an initializer list. – James McNellis Apr 13 '11 at 12:23
  • Or, more likely, you are using MFC and have mixed up debug and non-debug settings. – James McNellis Apr 13 '11 at 12:26
  • @James McNellis- Constructor definition.. public: CodeListSqlGenerator(IIntelligentCodeListUpgraderParameter *i_intelligent_codelist_upgrader_parameter); } – Greenhorn Apr 13 '11 at 12:32
  • @James McNellis - Yes I'm using MFC, can you brief me little more on debug and non-debug settings what I need to change – Greenhorn Apr 13 '11 at 12:36
  • I cannot, but there are other people who can. I just vaguely remember having had this issue before once; what I did to resolve it I do not remember. – James McNellis Apr 13 '11 at 14:50
  • 1
    Possibly something about a DEBUG_NEW macro interfering with every other definition of new. – Bo Persson Apr 13 '11 at 19:57
  • 1
    Like discussed here [http://stackoverflow.com/questions/1326656/is-there-a-way-to-automatically-have-a-define-reproduced-in-each-source-file](http://stackoverflow.com/questions/1326656/is-there-a-way-to-automatically-have-a-define-reproduced-in-each-source-file/1326779#1326779) – Bo Persson Apr 13 '11 at 20:04
  • 1
    Do you still get the same error if you write `#undef new` right before the line of code which is causing the error? – Adam Rosenfield Apr 14 '11 at 04:06
  • @AAdam Rosenfield and Bo Persso - No Im no longer getting the error, when #undef new thanks for the suggestion – Greenhorn Apr 14 '11 at 05:00

2 Answers2

1

DEBUG_NEW macro has to be change,. check whether you have included preprocessor #undef new, Try to write the #undef new before the new keyword

user736140
  • 44
  • 2
0

It looks like you are trying to create an ICodeListSqlGenerator object using the CodeListSqlGenerator constructor. This cannot be done, as ICodeListSqlGenerator already has its own constructor. However, a CodeListSqlGenerator object IS A ICodeListSqlGenerator, so you can create a CodeListSqlGenerator object and return the pointer to it as a ICodeListSqlGenerator pointer.

  • I'm not trying to create ICodeListSqlGenerator object, ICodeListSqlGenerator *i_codelist_sql_generator = new CodeListSqlGenerator(i_intelligent_codelist_upgrader_parameter); Creates reference of CodeListSqlGenerator object – Greenhorn Apr 14 '11 at 05:23
  • Umm... you do realize it actually creates the object and returns a pointer to the new object, right? – Carlos Daniel Gadea Omelchenko Apr 14 '11 at 05:59
  • Yes, an object reference rite ICodeListSqlGenerator is an Interface so I won't be able to create it object – Greenhorn Apr 14 '11 at 06:08