unable to overload function

How come this works for int and string but it wont for float?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>

using namespace std;

class Builtin{
	public:
		void print(std::string stringer);
		void print(int i);
		void print(float i);
};

void Builtin::print(std::string stringer){
	cout << stringer << std::endl;
}

void Builtin::print(int i){
	cout << i << std::endl;
}

void Builtin::print(float i){
	cout << i << std::endl;
}

int main(){
	Builtin build;
	build.print("test");
	build.print(1);
	build.print(1.1);

}
try using double instead of float
Or use float the specifier on your floating point number:
build.print(1.1f);
In C++ a floating point constant is considered a double unless told otherwise.

Topic archived. No new replies allowed.