468,512 Members | 1,338 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

Replace operator new question

Hello
Today, one of my friends said,"If you write a global operator new, you
will get a link error which complains new already defined in
msvcrt" (we are using MS VC++ 2005). I just said no, because C++
allows replacing global operator new. I have written a test, on static
lib with a global operator new, and an exe, and then all new linked to
my operator new. But he ask me, your operator new and the one defined
in msvcrt is just same function, how linker knows which to link? I can
not answer, anybody can tell me? Thanks a lot!
Nov 15 '07 #1
2 3194
Ne**********@gmail.com wrote:
Hello
Today, one of my friends said,"If you write a global operator new, you
will get a link error which complains new already defined in
msvcrt" (we are using MS VC++ 2005). I just said no, because C++
allows replacing global operator new. I have written a test, on static
lib with a global operator new, and an exe, and then all new linked to
my operator new. But he ask me, your operator new and the one defined
in msvcrt is just same function, how linker knows which to link? I can
not answer, anybody can tell me? Thanks a lot!
Most linkers will stop looking for a symbol once they found it. If you
make your function readily available, the linker will usually not use
the one that comes from the library listed later among the ones from
which to resolve symbols. More information is probably available in
a Microsoft Visual C++ newsgroup.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 15 '07 #2
Thanks for your reply.
I am looking for some articles on how linker works, would you like
give some links?
On Nov 15, 10:35 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
NeilFang2...@gmail.com wrote:
Hello
Today, one of my friends said,"If you write a global operator new, you
will get a link error which complains new already defined in
msvcrt" (we are using MS VC++ 2005). I just said no, because C++
allows replacing global operator new. I have written a test, on static
lib with a global operator new, and an exe, and then all new linked to
my operator new. But he ask me, your operator new and the one defined
in msvcrt is just same function, how linker knows which to link? I can
not answer, anybody can tell me? Thanks a lot!

Most linkers will stop looking for a symbol once they found it. If you
make your function readily available, the linker will usually not use
the one that comes from the library listed later among the ones from
which to resolve symbols. More information is probably available in
a Microsoft Visual C++ newsgroup.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 16 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by foo | last post: by
30 posts views Thread by | last post: by
5 posts views Thread by Mahesha | last post: by
21 posts views Thread by gary | last post: by
56 posts views Thread by spibou | last post: by
14 posts views Thread by inpuarg | last post: by
16 posts views Thread by spl | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.