We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hello, why is the destructor called twice for the first time?
class TestClass { public: TestClass() { printf("TestClass ctor\n"); } ~TestClass() { printf("~TestClass\n"); } }; RTTR_REGISTRATION { registration::class_<TestClass>("TestClass") .constructor<>()(policy::ctor::as_object) .constructor<>()(policy::ctor::as_raw_ptr) .constructor<>()(policy::ctor::as_std_shared_ptr) } int main(int argc, char** argv) { auto range = type::get<TestClass>().get_constructors(); std::vector<constructor> ctor_list(range.cbegin(), range.cend()); printf("00000000000000\n"); { variant var = ctor_list[0].invoke(); } printf("11111111111111\n"); { variant var = ctor_list[1].invoke(); type::get<TestClass>().destroy(var); } std::shared_ptr<TestClass> ptr; printf("22222222222222\n"); { variant var = ctor_list[2].invoke(); ptr = var.get_value<std::shared_ptr<TestClass>>(); } printf("333333333333333333\n"); ptr = NULL; printf("444444444444444444\n"); }
console output:
00000000000000 TestClass ctor ~TestClass ~TestClass 11111111111111 TestClass ctor ~TestClass 22222222222222 TestClass ctor 333333333333333333 ~TestClass 444444444444444444
The text was updated successfully, but these errors were encountered:
@tkzcfc You are not taking the copy/move constructors into consideration. Add:
TestClass(const TestClass&) { printf("TestClass ctor\n"); } TestClass(const TestClass&&) { printf("TestClass ctor\n"); }
And it works fine. Don't forget that with policy::ctor::as_object you are working with objects rather than pointers.
policy::ctor::as_object
Sorry, something went wrong.
No branches or pull requests
Hello, why is the destructor called twice for the first time?
console output:
00000000000000
TestClass ctor
~TestClass
~TestClass
11111111111111
TestClass ctor
~TestClass
22222222222222
TestClass ctor
333333333333333333
~TestClass
444444444444444444
The text was updated successfully, but these errors were encountered: