I need to convert from one struct to another with similar variables. I'm testing this on an example of two structs that have two ints.
For some reason it isn't assigning correctly, I believe that it is sending a local copy that is then deallocated? What am I doing wrong?
Thanks!
#include <iostream>
using namespace std;
struct a
{
int x, y;
a(){}
a(int _x, int _y)
{
x = _x;
y = _y;
}
};
struct b
{
int x, y;
b(){}
b(int _x, int _y)
{
x = _x;
y = _y;
}
b& operator=(const a& _a)
{
return b(_a.x, _a.y);
}
};
int main()
{
a a_test(1,2);
b b_test;
b_test = a_test;
std::cout << "a: " << a_test.x << "," << a_test.y << endl;
std::cout << "b: " << b_test.x << "," << b_test.y << endl;
return 0;
}