zoukankan      html  css  js  c++  java
  • c++中一个多态的实例

    #include <iostream>
    #include <fstream>
    #include <vector>
    #include <algorithm>
    using namespace std;
    
    class A{
    public:
        A(){
            a = 0;
        }
        int a;
    };
    
    class B :public A{
    public:
        B(){
            a = 1;
        }
        int a;
    };
    
    int main(){
        B b ;
        B *pb = &b;
        A* pa = &b;
    
        printf("a in B is: %d
    ", pb->a);
        printf("a in A is: %d
    ", pa->a);
    
        printf("value of pb is: %p
    ", pb);
        printf("value of pa is: %p
    ", pa);
    
        printf("address of pb->a is: %p
    ", &(pb->a));
        printf("address of pa->a is: %p
    ", &(pa->a));
    
        return 0;
    }

    结果如下:

  • 相关阅读:
    bash特性
    FHS 层级文件系统
    环境变量的问题
    linux认识
    搜索引擎的使用
    nginx
    部署操作手册
    git
    添加tag
    pycharm中使用git
  • 原文地址:https://www.cnblogs.com/wang-130213/p/9074129.html
Copyright © 2011-2022 走看看