Hello! In the code below, why does the counter not increment if I use Template arguments?
Code:#include <iostream>
using namespace std;
struct parent
{
int counter = 0;
parent() {};
};
struct child : parent
{
child() {};
};
template <typename A, typename B>
void f(A a, B b)
{
b.counter += 1;
cout << b.counter << endl;
}
int main()
{
child Anne;
child Pete;
for (int i = 1; i <= 5; ++i)
{
f(Anne, Pete);
f(Pete, Anne);
}
return 0;
}