I have a problem running this code All i am trying to do is creating a variadic template class that can give me sum of all the elements that are passed, (eg. 1,2,3,4,5,6 should give 21) whether its int or float, i could basically do it with two template functions recursively for which im getting the answer correctly but when im implementing it in class it doesnt give me answer
template <typename T>
class Myclass
{
public:
T sum;
T func(T A,T... B)
{
sum+=A;
func(B...);
}
T func(T A)
{
sum+=A;
return sum;
}
};
int main()
{
Myclass<int> myclass;
cout<<myclass.func(12,11,11,23);
return 0;
}
Aucun commentaire:
Enregistrer un commentaire