Mārtiņš Možeiko
2358 posts / 2 projects
Virtual function's disadvantage and real-life examples

I assume if you're asking if it it makes two unrelated pointers equal, not addresses of pointers. And yes, it does. And that's why it is an option - you can disable if you don't like hit.

Not sure what are you asking about my example? How can ptr() point anywhere than big() function? Look at the disassembly - there's no way it can point into middle of foo() and still return value 100000.

127 posts
Virtual function's disadvantage and real-life examples
Edited by longtran2904 on

Oh sorry, my bad. Not your example, I mean something like this:

int Foo() { return 1000; }
int Bar()
{
DoSomeOtherThing();
return Foo();
}
// Some other place
int (*f)(void) = CheckSomething() ? Foo : SomeOtherFunction; // Can this point to the end of Bar?


Mārtiņš Možeiko
2358 posts / 2 projects
Virtual function's disadvantage and real-life examples
Edited by Mārtiņš Možeiko on