S
srinivasarao_moturu
template<class T> Class ABC
{
public :
void SetValue(T k)
{ val = k; }
private:
T val;
};
int main()
{
ABC<int> tmp;
tmp.SetValue('A');
return 0;
}
In the above program compiler creates ABC<int> class because of
variable declaration tmp.
I passed character type to SetValue function so that there will be
implicit conversion from char to int and program works fine.
My doubt is, is there a way to capture this implicit conversion of
integral types by the compiler, instead of, smoothly converting from
char to int. My aim is, SetValue function should not accept the type
other Than T.
{
public :
void SetValue(T k)
{ val = k; }
private:
T val;
};
int main()
{
ABC<int> tmp;
tmp.SetValue('A');
return 0;
}
In the above program compiler creates ABC<int> class because of
variable declaration tmp.
I passed character type to SetValue function so that there will be
implicit conversion from char to int and program works fine.
My doubt is, is there a way to capture this implicit conversion of
integral types by the compiler, instead of, smoothly converting from
char to int. My aim is, SetValue function should not accept the type
other Than T.