I am learning C++ and I am wondering whether it is ever a good idea to use an object’s allocated memory address as a temporary application level identifier.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well, if you create the object with new(), the returned object instance pointer IS, effectively, the object. It becomes an application identifier until explicitly dispose()d. I try not to build objects on stacks – I write too much mutithreaded code and so it’s just too dangerous.
Obviously, there are many things you cannot do with addresses as ID – you cannot decrement/increment one to point at the object with the preceeding/succeeding ID, for example.