Skip to content
New issue

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

Repeated destructions #339

Open
tkzcfc opened this issue Jul 1, 2022 · 0 comments
Open

Repeated destructions #339

tkzcfc opened this issue Jul 1, 2022 · 0 comments

Comments

@tkzcfc
Copy link

tkzcfc commented Jul 1, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant