Quote:Original post by RealMarkP
Is there a way that I can check if the 'this' keyword was passed into a class
"The 'this' keyword" isn't a "thing" that can be passed. It's a way of obtaining a pointer to an object. (Also, "passed into a class" is nonsensical; you apparently mean "passed as a parameter to a constructor".)
There is no way to determine whether a pointer to an object was generated by code using the 'this' keyword or code not using the 'this' keyword, because either way, it's the same object, and thus, any pointers to the object are identical.
It almost seems like what you want is to enforce that the constructor is only called from member functions, and then check whether the passed-in value points to the object that initiated the call. But what do you think you could possibly accomplish by checking this, anyway? Show some code, so we can at least get closer to the question you really want to ask.
Quote:I know how to check if a pointer being passed in is on the Stack or the Heap
No, you don't. Not in a standards-compliant, platform-agnostic way, anyway - because it doesn't exist. If you are doing it by checking address ranges (the only thing I can think of), it won't necessarily work on any other platform.
Quote:but the 'this' keyword will always be on the Heap if the class itself was dynamically allocated.
Again, your terminology is sloppy. The 'this' keyword will yield a pointer to an object; and if that object was dynamically allocated, then the pointer will point to a heap location, because that's what "dynamically allocated" means. But this doesn't really have anything to do with what you're asking at all.
Quote:Original post by MaulingMonkeyQuote:Original post by Atrix256
You can always check if this == 0
The only way for this to ever be false...
I wonder if you realize that what you said could be interpreted as either exactly what you meant, or exactly the logical opposite :)