Click to See Complete Forum and Search --> : STL error - with declaration move to other .h file, please help.


vgrigor3
March 6th, 2003, 07:21 AM
In .cpp file I write:


#include "file.h"
#include <map>;
using namespace std;

class CPartHolder;

typedef map<int,CPartHolder*> type_MapPartHolder;
type_MapPartHolder mapPartHolder;

class CPartHolder
{
};



works fine
but if I move or add
declarations:

file.h :


#include <map>;
using namespace std;



into .h file
appeared STL error
"operator new not defined for...."

What is the reason of this and gow to resolve
such a problem?

Thanks

pim42
March 6th, 2003, 08:04 AM
Well I don't know much about C++ or STL ... basically just what people have taught me here. But I do know that you aren't suppose to have a "using namespace ..." in a header file. Instead write a "using" for each command you use, in your case "using std::map".

Also did you include the .h in the .cpp?

vgrigor3
March 6th, 2003, 08:10 AM
Your advice - not works.

Yves M
March 6th, 2003, 09:09 AM
In a header file, you should not use "using namespace std;", since otherwise all files which include this header will become "polluted" with the std namespace. But this seems not to be the problem here. Can you post a short succint, but compilable version of your .cpp and .h files that exhibit the problem ?

Graham
March 6th, 2003, 10:54 AM
When you moved the statements to the .h file, did you include that .h in the original .cpp?

vgrigor3
March 6th, 2003, 11:08 AM
I included .h file to the .cpp.

But I made it working by only making additional separate .h file
for map processing class and map definition.

reason for original error still not found by me.