Newsgroups: comp.std.c++ Path: utzoo!utgpu!cunews!csi.uottawa.ca!news From: hitz@sim5.csi.uottawa.ca (Martin Hitz) Subject: backward virtual function call Message-ID: <1991Apr30.024010.4331@csi.uottawa.ca> Sender: news@csi.uottawa.ca Nntp-Posting-Host: sim5 Organization: University of Ottawa Date: Tue, 30 Apr 91 02:40:10 GMT I wonder if the following is guaranteed to print 1: #include struct X { virtual f() { return 1; } }; struct Y : X { f() { return 2; } }; main() { X x; Y * y = (Y *) &x; cout << y->f(); } The ARM explains the usual case, that a call of f() for an object of class Y invokes Y::f(), even if it is called via a pointer to X, but I couldn't find anything about the above case. Zortech and g++ both yield 1 for this example. Is this considered to be the standard behaviour? Martin Hitz (hitz@csi.uottawa.ca)