0

This could be a duplicate[link] but, the answer is rather short and not very clear. In a possible implementation like this:

template <class T>
T * addressof(T & v)
{
  return reinterpret_cast<T *>(& const_cast<char&>(reinterpret_cast<const volatile char &>(v)));
}

why is the const_cast needed?

user2338150
  • 479
  • 5
  • 14
  • i posted it already... – user2338150 May 24 '17 at 12:14
  • don't create another question, just ask in comment. – jamek May 24 '17 at 12:15
  • okay, sure, but only this time.:) – user2338150 May 24 '17 at 12:16
  • 1
    btw... a flag as "Possible duplicate" isnt the end of the world. It just means that imho your question does not add enough to the linked question and that imho you could improve your question by making more clear what you thing is missing on that answer – 463035818_is_not_an_ai May 24 '17 at 12:18
  • 1
    @user2338150 The reason `const_cast` is required is because compiler won't allow you to implicitely cast away `const/volatile` qualifiers when doing `reinterpret_cast`. – freakish May 24 '17 at 12:20
  • @StoryTeller I think that the answer to the other question simply does not fully answer the question. It should not be accepted and OP should ask more questions in comments. – freakish May 24 '17 at 12:24
  • @StoryTeller I found a dupe that answers how the whole thing works. That should satisfy the OP – NathanOliver May 24 '17 at 12:25
  • @freakish - The dup Nathan linked is an exact one. It answer this question fully (The const cast is needed because of the reinterpret cast, because that is needed, due to). The link in the post, and the one tobi voted as a dup, is not one however. – StoryTeller - Unslander Monica May 24 '17 at 12:25
  • @NathanOliver - Yes, I was just agreeing with you :) – StoryTeller - Unslander Monica May 24 '17 at 12:26
  • Yes, this is the answer I've been looking for, possibly more.:) I'll read it fully first. Thank you for pointing me to the answer. – user2338150 May 24 '17 at 12:27
  • I did vote for reopen, because first it seemed like a "possible dupe" but turened out not to be a duplicate. Imho everything went well here and SO mechanics proved once again to work ok. However, what I dont like is the attidute of getting offended on the smallest critisism and imho OP should remove the "dismissive" from the question because it isnt appropriate to someone who took the time to write an answer (no matter how short it is) – 463035818_is_not_an_ai May 24 '17 at 12:29
  • @tobi303: I'll take that as constructive criticism, but obviously I had reason to get 'offended'. It occurred to me that you did not even read the question completely, as the link you posted was the same one mentioned in the question. Besides, the answer mentioned in the post was plainly '...'(fill in a more appropriate word if you must). Anyways, the point of asking and answering is for the benefit of more than both the parties. So, I'm removing the comment posted earlier, and I express my apologies if you found something rude. – user2338150 May 24 '17 at 18:34

0 Answers0