473,218 Members | 1,665 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,218 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
myclass.cpp
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 4059
weaknessforcats
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
weaknessforcats
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

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

Similar topics

30
by: | last post by:
I have not posted to comp.lang.c++ (or comp.lang.c++.moderated) before. In general when I have a C++ question I look for answers in "The C++ Programming Language, Third Edition" by Stroustrup....
6
by: Zenon | last post by:
Folks, I am having a terrible time overloading operators. I have tried what I thought was the correct way, I tried the cheating (friend declarations), all to no avail. Sorry for posting tons of...
3
by: Nimmi Srivastav | last post by:
There's a rather nondescript book called "Using Borland C++" by Lee and Mark Atkinson (Que Corporation) which presents an excellent discussion of overloaded new and delete operators. I am...
3
by: silver360 | last post by:
Hello, I'm trying to create a basic Heap manager and i have some question about new/delete overloading. The following code give me this output : >> $./heap >> registered : 0x804d098 >>...
9
by: learning | last post by:
hi I am trying to make some simple app to learn exception safety coding. I know that new and delete can throw bad_alloc but how can I force them to throw by a flag "change" at run time? I am...
3
by: Lighter | last post by:
The C++ Standard Doesn't Permit Overloading new and delete? In the 13.5 of The C++ standard (ISO/IEC 14882, 1998), I cannot find the specification on overloading the operators new and delete;...
2
by: m013690 | last post by:
Hi all, I'm having a problem with a program that continually generates assertion errors. After stepping through in the debugger and inserting several lines to track the progress, I've found...
5
by: Jerry Fleming | last post by:
As I am newbie to C++, I am confused by the overloading issues. Everyone says that the four operators can only be overloaded with class member functions instead of global (friend) functions: (), ,...
19
by: Jess | last post by:
Hello, After seeing some examples about operator overloading, I'm still a bit confused about the general syntax. The following is what I think, not sure whether it's correct. 1. For a unary...
8
by: Wayne Shu | last post by:
Hi everyone, I am reading B.S. 's TC++PL (special edition). When I read chapter 11 Operator Overloading, I have two questions. 1. In subsection 11.2.2 paragraph 1, B.S. wrote "In particular,...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.