In Visual Studio 2008, I started a new project based on the wizard for “Win32 Console Application” and using the MFC libraries. Then I added the necessary includes and libraries from ROOT. When I include TFile.h and create a new instance of a TFile (or basically any TObject-derived object) I get this compile error:
error C2661: ‘TObject::operator new’ : no overloaded function takes 3 arguments
Interestingly enough, the error goes away when I comment out the line
#define new DEBUG_NEW
which is created by the wizard. I don’t know if that line is important, so I can just leave it out, but I’m curious why this line causes a compile error with TObjects.
I attach the .cpp of my test project and I can provide the complete project on request.
I linked with ROOT 5.26/00.
rootproblem.cpp (844 Bytes)
In debug mode, Microsoft redefines the operator new, which then conflicts with the operator new defined in TObject…
to clarify this even more: Microsoft does an unbelievable thing, changing the definition of the C++ keyword “new” throughout your code to read DEBUG_NEW. They could just as well redefine “for” or “return”! Of course this breaks tons of code that uses new, e.g. as a member function. Really, un-be-lievable.
You did the right thing, uncommenting that #define. Thanks for letting us know!
to clarify this even more: Microsoft does an unbelievable thing, changing the definition of the C++ keyword …[/quote]
If only there were a way to use a non microsoft compiler on Windows with root.
(thinking really hard.)
Oh wait, there is.
(runs back under rock he came out of)
This is not a compiler problem, this problem appears only in automatically generated code (from Visual Studio)…
[quote=“bellenot”]This is not a compiler problem, this problem appears only in automatically generated code (from Visual Studio)…
Since my comment was somewhat silly and not relevant in the first place, I’ll let it go without adding ‘s|compiler|build environment|’