471,309 Members | 1,042 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,309 software developers and data experts.

Problems overloading new/delete operators for class

I have a class where I have defined the following overloaded methods:

static void*
operator new (size_t size, const std::nothrow_t&) throw ();

static void*
operator new (size_t size);

static void
operator delete (void* ptr) throw ();

static void
operator delete (void* ptr, const std::nothrow_t&) throw ();

I do this because I have a custom memory manager I use in some of my code to implement pooled memory. Anyhow later on I have a std::deque of these objects allocated and used. On Linux g++ this works fine but using Windows (Intel Compiler) I get the following error:

ICL /Qwd9,68,82,111,167,171,181,193,279,310,373,383,411 ,424,440,522,556,858,869,981,1418,1419,1599,1682,1 683,1684 /Zc:forScope /Qwd1572,1595 /Qwd188 /Qvc7.1 ... /Od /Zi /D_M_IX86=600 /DVOSD_DEBUG_BUILD myclass.cpp /Fo myclass.obj
C:\Program Files\Microsoft Visual Studio .NET 2003\VC7\INCLUDE\xmemory(42): error: no instance of overloaded "MyClass::operator new" matches the argument list
argument types are: (unsigned int, void *)
new ((void _FARQ *)_Ptr) _T1(_Val);
detected during:
instantiation of "void std::_Construct(_T1 *, const _T2 &) [with _T1=std::allocator<MyClass>::value_type, _T2=MyClass]" at line 147
instantiation of "void std::allocator<_Ty>::construct(std::allocator<_Ty> ::pointer, const _Ty &) [with _Ty=MyClass]" at line 593 of "C:\Program Files\Microsoft Visual Studio .NET 2003\VC7\INCLUDE\deque"
instantiation of "void std::deque<_Ty, _Ax>::push_back(const _Ty &) [with _Ty=MyClass, _Ax=std::allocator<MyClass>]"

So its apparently looking for some different operator new. But I have no clue why (what is the puspose of this non-standard new operator) nor why even if needed its an issue (since the default one should exist since its not overloaded). ANy ideas?
Jun 26 '07 #1
5 3787
9,208 Expert Mod 8TB
C:\Program Files\Microsoft Visual Studio .NET 2003\VC7\INCLUDE\xmemory(42): error: no instance of overloaded "MyClass::operator new" matches the argument list
argument types are: (unsigned int, void *)
new ((void _FARQ *)_Ptr) _T1(_Val);
Do I read this correctly: Line 42 of the Visual Studio standard header xmemory knows about MyClass::operator new???
Jun 26 '07 #2
Thats what I am seeing. Odd isn't it. I am using the Intel compiler with this (is 100% compatabile with MS stuff) so maybe something in its error reporting is picking this up.

I have other places where this same type of thing works, but not sure they every get used in the STL (or in MS devs case NQSTL, as in Not Quite-STL). And its even weirder that its lookinf for a new operator with a non-standard interface.
Jun 26 '07 #3
9,208 Expert Mod 8TB
Try your code on Visual Studio.NET 2005. If what you say is true, it will fail.

My guess is it will not fail. I am leery of 100% conmpatible. I have never seen that.

If you don't have Visual Studio.NET 2005, send some code aand I will try it.
Jun 26 '07 #4
I'll try to find 2005 .NET and see what happens. It would be too dififuclt to try and get code to someone to compile as the surrounding code is huge, especially when using the pooled memory manager.

When I say 100% compaatible, thats because the Intel compiler is a compiler only. It still relies on MSDev Studio installed, basically its just a different version of CL, it does not include its own runtime, headers, or distributed files. So even if there was a compatability problem, the code is not even getting that far, its getting lost in the MSDev 2003 .NET <deque> file.

I guess for now I'll just turn this off in my code nad not overload the new operator, it compiles fine that way, just much slower.
Jun 26 '07 #5
Seems that it's a placement new operator. Not sure why its not picking up the standard one, but thats what your looking for. Memory has already been allocated it needs to be reserved and initialized.
Jun 26 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

30 posts views Thread by | last post: by
6 posts views Thread by Zenon | last post: by
3 posts views Thread by Nimmi Srivastav | last post: by
3 posts views Thread by silver360 | last post: by
9 posts views Thread by learning | last post: by
2 posts views Thread by m013690 | last post: by
5 posts views Thread by Jerry Fleming | last post: by
19 posts views Thread by Jess | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.