阅读背景:

c ++多态((X *)y) - > foo()vs((X)* y).foo()

来源:互联网 

Suppose Y is a derived class from class X and X declares foo to be virtual. Suppose y is of type (Y*). Then ((X*)y)->foo() will execute the Y version of foo(), but ((X)*y).foo() will execute the X version. Can you tell me why polymorphism does not apply in the dereferenced case? I would expect either syntax would yield the Y version of foo().Suppose Y is a derived class from class X and X




你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: