Actually this isn't sending a message to an object at all, and I
think your example illustrates this perfectly.
C++ will invoke the function, passing as the 0th parameter the
pointer given by the value of x. The function in class a will attempt
to de-reference that pointer as a "b" object, but will overrun the
memory allocated to the address and you'll get either a SEGV or
memory corruption.
Do this in the Objective C (or Smalltalk 80, or Ruby) runtime, and
you will get a safe "method not found" error at runtime, with no
danger of memory corruption, because in the ObjC RT the object type
is included in the object record.
Chris is absolutely right.
Cheers,
Ben
On 18/05/2005, at 4:40 PM, Chris Dillman wrote:
Do you mean like this?
class a{
public:
void foo();
void bar();
};
class b{
public:
int y;
void foo2(){
y = 100;
}; };
int main (int argc, char * const argv[]) {
a my_a;
int x = &my_a;
( (b*) (x) )->foo2();
return 0;
}
My thoughts if this is what you mean.
1. Memory corruption is bad.
2. You still need to type caste the Ptr to get it by the compiler.
3. You succeed on calling a function on a object that can not
support it.
So is this at all useful?
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
|