3
I want to do functions with variant input type, like this:
int count(vector<auto> base, auto val)
{
int sum= 0;
for (auto it : base)
{
if (it == val)
{
sum++;
}
}
return sum;
}
or this:
string str(auto a)
{
stringstream x;
x << a;
return x.str();
}
But of course, it didn’t work. I received the following error:
error: invalid use of 'auto'
How can I do that?
You need to explain better what you want, there’s a guy who wants to use one template, but the question says nothing.
– Maniero
I have no idea what a template
– Felipe Nascimento
So explain what you want to do so we can help you..
– Maniero
@bigown, I realized how stupid my question was. Post updated.
– Felipe Nascimento
@Felipenascimento, there are stupid questions, and there are questions like that. It may be trivial for those who know, but for those who are starting out in the field, even the most trivial can be new
– Jefferson Quesado