My code is something like this:
// ... code
template <int i>
int modifyparameter()
{
i = i++;
return i;
}
// ... some more code
int main()
{
int answer = modifyparameter<5>();
cout << answer; //expecting 6
}
But I am getting errors. What have I done wrong?
i
is the name of an int value, and you cannot modify values. You probably want one of these:
template <typename Number>
Number functional(Number x)
{
return x + 1;
}
template <typename Number>
Number& side_effect(Number& x)
{
return ++x;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With