zoukankan      html  css  js  c++  java
  • 面试笔试题(1)

    1. 纯虚函数,不能定义变量

    #include <iostream>
    using namespace std;
    class  A
    {
        public:
        virtual void f() = 0;
    };
    int main()
    {
        A a;
        a.f();
        return 0;
    }
    

    2.  虚函数是可以实现的

    #include <iostream>
    using namespace std;
    class  A
    {
        public:
        virtual void f()
        {
            cout << "hello world" << endl;
        }
    };
    int main()
    {
        A a;
        a.f();
        return 0;
    }
    

      3. 纯虚函数是可以实现的

    #include <iostream>
    using namespace std;
    class  A
    {
        public:
        virtual void f() = 0;
    };
    void A ::f()
    {
        cout << " hello world" << endl;
    }
    int main()
    {
        return 0;
    }
    

      4.   f() 是可以在子类中实现的

    #include <iostream>
    using namespace std;
    class  A
    {
        public:
        virtual void f() = 0;
    };
    class B :public A
    {
        public:
        void f()
        {
            cout << "hello world" << endl;
        }
    };
    int main()
    {
        B b;
        b.f();
        return 0;
    }
    

      

  • 相关阅读:
    d3-tree 双向树
    .gitignore
    url正则匹配
    this 指向
    git 用法小总结
    心态崩了?
    内存溢出和内存泄漏的区别
    jQuery添加方法
    物理像素与逻辑像素
    服务器返回的status
  • 原文地址:https://www.cnblogs.com/hitwtx/p/2190570.html
Copyright © 2011-2022 走看看