Been spending the last few days trying to relearn C++. I messed around with it many years ago (back in the 90's), many things I've forgotten and many changes to the language.
Made this handy little class which stores two numbers in a range and interpolates between them by subscripting an array with a double.
#include <iostream>
class Range
{
private:
double m_start, m_finish;
public:
Range(double start, double finish) : m_start(start), m_finish(finish) {}
double operator[](const double inter)
{
return (m_finish-m_start)*inter+m_start;
}
};
int main()
{
Range range(10,20);
for(double i = 0.0;i <= 1.0; i += 0.1)
std::cout << range[i] << ' ';
std::cout << std::endl;
Range range2(100,50);
for(double i = 0.0; i <= 1.0; i += 0.1)
std::cout << range2[i] << ' ';
std::cout << std::endl;
}