I'm using Visual Studio 2015 Update 3 and encountered the following warning while writing a simple class which basically is just a wrapper around an int.
The example below is not the actual class but a shorter example resulting in the same warning :
class Foo {
public:
Foo() : x(23) {}
Foo(int xx) : x(xx) {}
Foo(const Foo& other) : x(other.x) {}
Foo& operator++(int junk) {
Foo copy(*this);
this->x += 5;
return copy;
}
int x;
};
In line 12 (return copy
) I get the following warning:
warning C4172: returning address of local variable or temporary: copy
I'm confused because I think I'm not really returning an address or temporary because I thought the copy constructor of Foo would take care of such situations.
I would be really happy if someone could tell me what I'm missing here.
Also I found implementations of post increment operators just like this one in other stackoverflow articles as well (e.g. C++: overloading ++ for both pre and post increment
Thank you all in advance.