Linker error LNK2001 with bools

M

Mike

Got a wierd one here.

I have a class function with 4 parameters, defined like

myclass::myfunc(size_t p1, size_t p2, size_t p3 = 1, bool p4 = TRUE)

If I then call that function like

myptr->myfunc(1,2,3,FALSE);

I get a link error..

myprog.obj : error LNK2001: unresolved external symbol "public: void
__thiscall myclass::myfunc(unsigned int,unsigned int,unsigned int,int)"
(?myfunc@myclass@@QAEXIIIH@Z)
Debug/myprog.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

rf_modem.exe - 2 error(s), 0 warning(s)

However, if I change the definition and implementation, changing the
bool to another unsigned int, it all builds without any problems.

Anyone got any comments on why this should be ? It's MS Visual C++ V6
 
B

Bjoern Paetzel

Got a wierd one here.
myclass::myfunc(size_t p1, size_t p2, size_t p3 = 1, bool p4 = TRUE)

You may want to use C++ by replacing 'TRUE' with 'true' here ..
myptr->myfunc(1,2,3,FALSE);

... and 'FALSE' with 'false' here.
However, if I change the definition and implementation, changing the bool
to another unsigned int, it all builds without any problems.

Anyone got any comments on why this should be ? It's MS Visual C++ V6

I assume TRUE and FALSE are of type unsigned int there.
 
J

John Harrison

Mike said:
Got a wierd one here.

I have a class function with 4 parameters, defined like

myclass::myfunc(size_t p1, size_t p2, size_t p3 = 1, bool p4 = TRUE)

If I then call that function like

myptr->myfunc(1,2,3,FALSE);

I get a link error..

myprog.obj : error LNK2001: unresolved external symbol "public: void
__thiscall myclass::myfunc(unsigned int,unsigned int,unsigned int,int)"
(?myfunc@myclass@@QAEXIIIH@Z)
Debug/myprog.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

rf_modem.exe - 2 error(s), 0 warning(s)

However, if I change the definition and implementation, changing the
bool to another unsigned int, it all builds without any problems.

Anyone got any comments on why this should be ? It's MS Visual C++ V6

Are you sure you are not mixing up bool and BOOL? You are definitely mixing
up false and FALSE, true and TRUE (it should be false and true).

Look out for #defines like this '#define bool int' or '#define bool BOOL'.
It's clear from your error message that your compiler is interpreting bool
as int. That could be because somewhere in your code you have #define bool
....

john
 
M

Mike

John said:
Are you sure you are not mixing up bool and BOOL? You are definitely mixing
up false and FALSE, true and TRUE (it should be false and true).

Look out for #defines like this '#define bool int' or '#define bool BOOL'.
It's clear from your error message that your compiler is interpreting bool
as int. That could be because somewhere in your code you have #define bool
...

john

Ha! you were right there was an include file that redefined true, false
and bool.

Thanks.
 

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,281
Latest member
Pedroaciny

Latest Threads

Top