Moreshwar Salpekar Posted October 19, 2021 Report Share Posted October 19, 2021 Hello, This may have been asked earlier but I cant find it so I am asking again. If it is already asked, please let me know the link I have two possible extensions A and B (for simplicity only). Both are derived from tlm_extension I have a module name MOD (for simplicity again). In this I am checking if extension A is attached or not. I am not checking the extension B in MOD. It is just for tracking purposes. Extension A may or may not be present. Therefore, i am making check like this A *extA; req->get_extension(ext); // tlm::tlm_generic_payload *req is the declaration if (extA == nullptr) { do ActionX } else { do ActionY } Now what is happening is while sending a request to MOD, I attach extension B. There is not extension A attached. Therefore, I think that the check if (extA == nullptr) should return true. However, this is not the case. gdb is showing extA is actually B when doing p *extA. I think this is because both A and B are derived from tlm_extension. Is there anyway, I can do a correct check so that if extension A is not present, it should extA as nullptr especially when A is not present but B is present.? Regards Moreshwar Quote Link to comment Share on other sites More sharing options...
Moreshwar Salpekar Posted October 19, 2021 Author Report Share Posted October 19, 2021 I cant delete this post. Quote Link to comment Share on other sites More sharing options...
Eyck Posted October 29, 2021 Report Share Posted October 29, 2021 The problem is that the pointer is not initialized. So : A *extA{nullptr}; req->get_extension(ext); // tlm::tlm_generic_payload *req is the declaration if (extA == nullptr) { do ActionX } else { do ActionY } should do the trick. BTW , a better soultion would be: auto* extA = req->get_extension<A>(); if (extA == nullptr) { do ActionX } else { do ActionY } or even more concise: if (auto* extA = req->get_extension<A>()) { do ActionY } else { do ActionX } Quote Link to comment Share on other sites More sharing options...
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.