c++ - reinit variable with default constructor plus assigment -


consider such code:

struct foo {     int a;     foo() { = 17; }     //void clear() { = 17; } };  class boo { public:     void f() {         foo = foo();         //foo.clear();     } private:     foo foo; }; 

i compiled gcc (-std=c++11), , according logs in f function foo not reintialized foo = foo(); expression, works fine if uncomment code clear.

is code foo = foo(); should translated to

foo tmp; memcpy(&foo, &tmp, sizeof(foo)); 

or compiler can kind of optimization, , after foo = foo(); got garbage in foo?

this:

foo = foo(); 

should construct new instance of class foo.

it creates new object, allocating memory , initializing data member a 17.


ps: error somewhere else, , since refused provide minimal example, can't tell where.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -