I am new to template classes, and tried to implement a very simple program, just to try out the functionality and syntax. I initialise a template class distance, and then try to get the data and display it.
#include<iostream>
using namespace std;
template <class T>
class distance {
T feet;
T inches;
public:
distance ()
{
}
T getdata (T f, T i)
{
feet=f;
inches=i;
}
void showdata ()
{
cout<<"Distance is "<<feet<<" feet and "<<inches<<" inches";
}
};
int main ()
{
distance <int> x;
x.getdata(5,7);
x.showdata();
}
However, on the distance <int> x
line, I get the error stating 'error: reference to 'distance' is ambiguous'. I am not able to figure out my error.