CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2002
    Posts
    309

    STL error - with declaration move to other .h file, please help.

    In .cpp file I write:

    Code:
    #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 :

    Code:
    #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
    Last edited by vgrigor3; March 6th, 2003 at 12:10 PM.

  2. #2
    Join Date
    Jan 2003
    Posts
    159
    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?

  3. #3
    Join Date
    Aug 2002
    Posts
    309
    Your advice - not works.

  4. #4
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588
    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 ?
    Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
    Supports C++ and VB out of the box, but can be configured for other languages.

  5. #5
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470
    When you moved the statements to the .h file, did you include that .h in the original .cpp?
    Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
    --
    Sutter and Alexandrescu, C++ Coding Standards

    Programs must be written for people to read, and only incidentally for machines to execute.

    --
    Harold Abelson and Gerald Jay Sussman

    The cheapest, fastest and most reliable components of a computer system are those that aren't there.
    -- Gordon Bell


  6. #6
    Join Date
    Aug 2002
    Posts
    309
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured