cpp/object_oriented/virtual_function #33
Replies: 3 comments 1 reply
-
第一段代码乱了。应该是 class Point {
public:
Point(float xval );
virtual ~Point();
float x() const;
static int PointCount();
protected:
virtual ostream& print( ostream &os ) const;
float _x;
static int _point_count;
}; |
Beta Was this translation helpful? Give feedback.
0 replies
-
其中第一条很重要,当我们使用派生类的指针去访问/调用虚函数时,实际上并未发生动态多态,因为编译时就能确定对象类型为派生类型,然后直接生成调用派生类虚函数的代码即可,这种叫做静态绑定。 |
Beta Was this translation helpful? Give feedback.
1 reply
-
最上面Point类的对象模型有问题,vptr在float x的前面 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
cpp/object_oriented/virtual_function
编程指北: 计算机系统学习指南, 操作系统, 计算机网络, C++, Java, 算法, 数据结构
https://csguide.cn/cpp/object_oriented/virtual_function.html
Beta Was this translation helpful? Give feedback.
All reactions