0

Is there a way in C++ to deal with this? (a way to force that a boolean is strictly a boolean and cannot be converted to another numerical type?)

line 42: Error: Overloading ambiguity between "MultiLog::writeLog(const long&)" and "MultiLog::writeLog(const bool&)"

3
Contributors
7
Replies
8
Views
11 Years
Discussion Span
Last Post by winbatch
0

you might have some other problem. This works ok for me

#include <iostream>
using namespace std;

void foo(const long& l)
{
	cout << l << endl;
}

void foo(const bool& l)
{
	cout << l << endl;

}


int main(int argc, char* argv[])
{
	bool b = true;
	foo(b);
	return 0;
}
0

What about if you pass a long to the function in main?

no problem with that either. why don't you post your program (zip it up first if its pretty long)

0

I figured it out. When I pass an int, it can't decide whether to use the bool or the long. I think I just need to create an int version of the function as well...

0

or use a template?? I'm not very good at them, so don't ask me how.

I could use a template or do the cast, the problem is that I want to do special processing based on the type (ie if it's a bool, then print it out as 'TRUE' or 'FALSE', etc. By adding the function for int, it worked out fine.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.