- #1
yungman
- 5,755
- 293
This is actually very simple. I think the normal way is done like this:
But this is from the Ivor book:
I have no idea what the book is doing, what is inRange<double, 100, 500>(val2);? I never seen this before. Is this something newer than my old Gaddis book again?
Thanks
C++:
#include<iostream>
using namespace std;
template<class T2>
auto inRange(const T2& value, int low, int hi)
{
if ((value <= hi) && (value >= low)) return "It is in range.";
else return " It is out of range.";
}
int main()
{
int val1 = 99;
cout << inRange(val1, 100, 500) << "\n\n";
return 0;
}
C++:
#include<iostream>
using namespace std;
template<class T1, int low, int hi>//how does this work
auto inRange(const T1& value)
{
if ((value <= hi) && (value >= low)) return "It is in range.";
else return " It is out of range.";
}
int main()
{
int val2 = 200;
cout << inRange<double, 100, 500>(val2);//what is this, it not in the function parameter
cout << "\n\n";
return 0;
}
I have no idea what the book is doing, what is inRange<double, 100, 500>(val2);? I never seen this before. Is this something newer than my old Gaddis book again?
Thanks