Error When Trying to Use Fstream

LyTning94

Dragonborn
Joined
Nov 10, 2010
Messages
397
Location
Skyrim
I'm trying to use fstream for some necessary file I/O in my mod, but I'm getting the following error:

fstream (465) error C2061: syntax error : identifier '_DebugHeapTag'

Does anyone have any idea why this is occurring?

EDIT: I've been looking for a solution online and saw a suggestion to comment out all defines of the keyword new. I found this in CvGameCoreDLLDefNew.h:

Code:
#define new new(__FILE__, __LINE__)

I commented this out and it's compiling fine, but I'm guessing it's not a good idea to leave this commented out. Why would this line cause an error with fstream, and how can I get around this?

BTW, Merry Christmas to everyone! :)
 
I'm guessing a more immediate question might be: what purpose does USE_MEMMANAGER serve? It is only defined in Debug mode, and it must be defined for the code in CvGameCoreDLLDefNew.h, including the line I posted above, to take effect. All the #defines in CvGameCoreDLLDefNew.h call overloaded operators also included in the file, and all those eventually call this function in CvDLLUtilityIFaceBase.h

Code:
virtual void* newMem(size_t size, const char* pcFile, int iLine) = 0;

Unfortunately this function doesn't do me much good because it's a pure virtual function, and the classes derived from CvDLLUtilityIFaceBase are all (of course) in the exe.

Since it's only used in debug mode anyway, I'm wondering if it was just used for debugging, and really has no other purpose. In this case I could just disable it permanently, but I don't want to do this if it's going to cause problems somewhere.
 
This is used for debugging memory leaks and such. It causes all (or most) allocations to use a debug version of the C runtime which keeps for each allocation the place in code in which it was done.
So you can comment it out safely.

BTW, unlike what elkvis told you (I can google too ;) ), of course you can use new as a preprocessor macro. It might be a little confusing, but it works.
It happens right here :)
 
Thanks, Asaf! We can always count on you to work out our problems for us. :king:

BTW, unlike what elkvis told you (I can google too ;) )...

I guess you can :lol:. He was right in a way though, because the #define still calls this overloaded operator:

Code:
void* operator new(size_t size, char* pcFile, int iLine);

EDIT: I'm just curious--why was this causing an error in fstream anyway?
 
This is a guess based on C++ knowledge and not on familiarity with Microsoft's STL implementation (which fstream is a part of):

The overloaded operator new defined in the DLL is a global new. basically you can overload it with whichever parameters you want (in addition to the mandatory size_t), but file/line is the standard for debugging.

In addition, each class has its own new and delete operators. By default the compiler just uses the global ones but you can override them in each class.
Now, because of the #define, the new call is translated to new(file,line), and since I guess the fstream class has its own new operator, but no new(file,line) operator, the compiler has a problem.
There are some issues here which I'm not completely certain of, but I think that fits.

And anyway, instead of commenting it out and changing it for the entire DLL, you can do something like this:

Code:
#include "CvGameCoreDLLUndefNew.h"
#include <fstream>
#include "CvGameCoreDLLdefNew.h"

It seems to eliminate the problem.
 
And anyway, instead of commenting it out and changing it for the entire DLL, you can do something like this:

Code:
#include "CvGameCoreDLLUndefNew.h"
#include <fstream>
#include "CvGameCoreDLLdefNew.h"

It seems to eliminate the problem.

Good idea, I should have thought of that. Thanks again.
 
Back
Top Bottom