Replace operator new question

N

NeilFang2008

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!
 
V

Victor Bazarov

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
 
N

NeilFang2008

Thanks for your reply.
I am looking for some articles on how linker works, would you like
give some links$B!)(B
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,265
Latest member
TodLarocca

Latest Threads

Top