c++ - order of constructor execution -


does code expect do? meaning, handle_(curl_easy_init()) part called before or after constructor body execution?

class oauth2 { public:     oauth2() : handle_(curl_easy_init()) {         if (handle_ == null) {             throw new runtime_error("curl_easy_init return null");         }     }     ~oauth2() {         curl_easy_cleanup(handle_);     } private:     curl * handle_; }; 

thanks

is handle_(curl_easy_init()) part called before or after constructor body execution?

it called before execution of constructor body.


c++ standard n3337 § 12.6.2.10:

initializing bases , members

in non-delegating constructor, initialization proceeds in following order:

— first, , constructor of derived class (1.8), virtual base classes initialized in order appear on depth-first left-to-right traversal of directed acyclic graph of base classes, “left-to-right” order of appearance of base classes in derived class base-specifier-list.

— then, direct base classes initialized in declaration order appear in base-specifier-list (regardless of order of mem-initializers).

then, non-static data members initialized in order declared in class definition (again regardless of order of mem-initializers).

— finally, compound-statement of constructor body executed.

the delegating constructor in excerpt defined constructor calls constructor of same class (so delegates job). in such case former called principal constructor while latter called target constructor.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -