I want to build a class that throws an exception if the parameter list is of the wrong type,
For example this class: in the header
class rectangle
{
public:
rectangle(int, int);
int getarea();
private:
int length;
int width;
};
in cpp
rectangle::rectangle(int l, int w)
{
if (l!=int|| w!=int)
throw string("Exception found!");
length=l;
width=w;
}
I want the constructor to throw an exception if it is called in the following ways in the main program:
rectangle rec1(3.5, 4);
rectangle rec1(a, 5);
because 3.5 and a are not of type int. How can I check if the argument of the constructor is of the desired type?