How to restrict automatic Type conversation in C++?

I want to restrict automatic type conversation in C++ function calls.

I have the below piece of code in which a function is called which takes an int value, but while calling the same a float value is passed.
I want to restrict this.
Now it is showing a compile time warning message.
But I need an error message instead of the warning one.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
using namespace std;

class A
{
public:
	void display(int value)
	{
		cout<<"Passed Value :: "<<value<<endl;
	}
};

int main()
{
	float floatValue = 5.5f;

	A a;

	/// Below statement should give an error as float value
	/// is being passed instead of integer value.
	a.display(floatValue);
	
	return 0;
}


Please share some views in this regard.
You can set the compiler to report warnings as errors.
Declare a private overload for the types you don't want:
1
2
3
4
5
6
7
8
9
class A
{
    void display ( double value ); // discards double and float
public:
	void display(int value)
	{
		cout<<"Passed Value :: "<<value<<endl;
	}
};


1
2
3
4
5
6
7
8
9
10
class A
{
    template < class T >
        void display ( T value ); // with this, the compiler should accept only int
public:
	void display(int value)
	{
		cout<<"Passed Value :: "<<value<<endl;
	}
};
I agree with kbw's solution.
Topic archived. No new replies allowed.