[想多了]c++的this指针不是动态绑定的
来源:互联网 发布:淘宝上的驱鼠器 编辑:程序博客网 时间:2024/05/16 16:21
结论如题:
设计实验如下
#include <cstdio>class A{ int length; int width;public: A(int _length = 1,int _width = 2) { length = _length; width = _width; } int Area() { return this->length*this->width; }};class B: public A{ int length; int width;public: B(): A(){ length = 3; width = 4; }};intmain(int argc, char* argv[]){ B b; std::printf("%d", b.Area());}结果输出了2
而不是12,说明this指针指向内部的A,而不是根据实例的类型判断读取B
某种程度上这样的静态绑定才是合理的~
想多了
0 0
- [想多了]c++的this指针不是动态绑定的
- C ++的this指针
- javascript的动态this与动态绑定
- java中this的动态绑定
- C++this指针的理解
- C++this指针的理解
- C++this指针的用法
- 【c++】this指针的使用
- 【C++】隐含的this指针
- Java的动态绑定、静态绑定和this、super
- TreeView的动态绑定(C#)
- this指针与静态绑定及动态绑定
- C++this指针的理解和用法
- C++this指针的理解和用法
- 【C++】:C++之this指针的作用
- 【c++】this 指针和类的继承
- this的绑定规则
- js的动态绑定事件和静态绑定事件的this的指向
- 全局变量和静态全局变量
- 在ubuntukylin13.10上面安装iNode
- 新浪微博API-friends
- 关于调试GPS45711的记录
- MyBatis 通过包含的jdbcType类型
- [想多了]c++的this指针不是动态绑定的
- javase基础之 集合框架概述
- 数据结构与算法分析-01 起步
- 3.11周二 概率 离散
- 解决Access denied for user 'walter'@'localhost' (using password: YES)
- Tyvj 1055 沙子合并 DP
- DevExpress中自定义CellTemplate数据绑定不显示的问题
- C#中深复制的几种方法
- 生成一定范围内的互不相同的随机数的方法比较