Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Question about operator new

Question about operator new

Scheduled Pinned Locked Moved C / C++ / MFC
c++questionsharepointperformancehelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    I was reading Item 7 of Scott Meyer's book, Effective C++ and decided to try the code. So I created my template header , a file that inherits from the template class and a driver (i.e. simple main) that tries to instantiate the new class. I got the following errors on VC6 SP 5. Any ideas of what I am doing wrong? code is included below: driver.cpp c:\processdoc\c++\memorymanager\test.h(26) : error C2039: 'set_new_handler' : is not a member of 'std' C:\ProcessDoc\C++\MemoryManager\driver.cpp(11) : while compiling class-template member function 'void *__cdecl NewHandlerSupport::operator new(unsigned int)' c:\processdoc\c++\memorymanager\test.h(35) : error C2039: 'set_new_handler' : is not a member of 'std' C:\ProcessDoc\C++\MemoryManager\driver.cpp(11) : while compiling class-template member function 'void *__cdecl NewHandlerSupport::operator new(unsigned int)' c:\processdoc\c++\memorymanager\test.h(39) : error C2039: 'set_new_handler' : is not a member of 'std' C:\ProcessDoc\C++\MemoryManager\driver.cpp(11) : while compiling class-template member function 'void *__cdecl NewHandlerSupport::operator new(unsigned int)' main.cpp Error executing cl.exe. MemoryManager.exe - 3 error(s), 0 warning(s) And here is the code I have: the main driver (driver.cpp): #include "main.h" void main(void) { x * yyy = new x(); } the class (main.cpp & main.h): #include "main.h" x::x() { } x::~x() { } void x::test() { } //////main.h #include "test.h" class x : public NewHandlerSupport { public: x(); ~x(); void test (); private: }; the template (right off SM's book)..I called it test.h : #include template class NewHandlerSupport { public: static new_handler set_new_handler(new_handler p); static void * operator new(size_t size); private: static new_handler currentHandler; }; template new_handler NewHandlerSupport::set_new_handler(new_handler p) { new_handler oldHandler = currentHandler; currentHandler = p; return oldHandler; } template void * NewHandlerSupport::operator new(size_t size) { new_handler globalHandler = std::set_new_handler(currentHandler); void *memory; try { memory = ::operator new(size); } catch (std::bad_alloc&) { std::set_new_handler(globalHandler); throw; } std::set_new_handler(globalHandler); return memory; } // this sets each Curren

    B 1 Reply Last reply
    0
    • L Lost User

      I was reading Item 7 of Scott Meyer's book, Effective C++ and decided to try the code. So I created my template header , a file that inherits from the template class and a driver (i.e. simple main) that tries to instantiate the new class. I got the following errors on VC6 SP 5. Any ideas of what I am doing wrong? code is included below: driver.cpp c:\processdoc\c++\memorymanager\test.h(26) : error C2039: 'set_new_handler' : is not a member of 'std' C:\ProcessDoc\C++\MemoryManager\driver.cpp(11) : while compiling class-template member function 'void *__cdecl NewHandlerSupport::operator new(unsigned int)' c:\processdoc\c++\memorymanager\test.h(35) : error C2039: 'set_new_handler' : is not a member of 'std' C:\ProcessDoc\C++\MemoryManager\driver.cpp(11) : while compiling class-template member function 'void *__cdecl NewHandlerSupport::operator new(unsigned int)' c:\processdoc\c++\memorymanager\test.h(39) : error C2039: 'set_new_handler' : is not a member of 'std' C:\ProcessDoc\C++\MemoryManager\driver.cpp(11) : while compiling class-template member function 'void *__cdecl NewHandlerSupport::operator new(unsigned int)' main.cpp Error executing cl.exe. MemoryManager.exe - 3 error(s), 0 warning(s) And here is the code I have: the main driver (driver.cpp): #include "main.h" void main(void) { x * yyy = new x(); } the class (main.cpp & main.h): #include "main.h" x::x() { } x::~x() { } void x::test() { } //////main.h #include "test.h" class x : public NewHandlerSupport { public: x(); ~x(); void test (); private: }; the template (right off SM's book)..I called it test.h : #include template class NewHandlerSupport { public: static new_handler set_new_handler(new_handler p); static void * operator new(size_t size); private: static new_handler currentHandler; }; template new_handler NewHandlerSupport::set_new_handler(new_handler p) { new_handler oldHandler = currentHandler; currentHandler = p; return oldHandler; } template void * NewHandlerSupport::operator new(size_t size) { new_handler globalHandler = std::set_new_handler(currentHandler); void *memory; try { memory = ::operator new(size); } catch (std::bad_alloc&) { std::set_new_handler(globalHandler); throw; } std::set_new_handler(globalHandler); return memory; } // this sets each Curren

      B Offline
      B Offline
      Bret Faller
      wrote on last edited by
      #2

      Its telling you that set_new_handler function is not a member of the namespace std. Instead of std::set_new_handler you should use NewHandlerSupport::set_new_handler Bret Faller Odyssey Computing, Inc.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups