Jerome Posted January 12 Report Posted January 12 A *item = A::type_id::create("item", this); I am curious about the difference from systemverilog? should I delete item by myself, or will uvm systemc lib totally take over it? Quote
Eyck Posted January 12 Report Posted January 12 You need to take care yourself as the factory just calls new and returns a raw pointer. You should use a std::unique_ptr to hold the raw pointer: #include <memory> std::unique_ptr<A> a{A::type_id::create("item", this)}; or if you have to keep declaration and initialization separate: #include <memory> std::unique_ptr<A> a; a.reset(A::type_id::create("item", this)); This way C++ takes care of destruction properly Quote
Jerome Posted January 12 Author Report Posted January 12 your reply is very helpful. 1 hour ago, Eyck said: You need to take care yourself as the factory just calls new and returns a raw pointer. You should use a std::unique_ptr to hold the raw pointer: #include <memory> std::unique_ptr<A> a{A::type_id::create("item", this)}; or if you have to keep declaration and initialization separate: #include <memory> std::unique_ptr<A> a; a.reset(A::type_id::create("item", this)); This way C++ takes care of destruction properly Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.