相关疑难解决方法(0)

如何通过编译器解决函数?

如何确定以下调用是在编译时还是在运行时绑定?

object.member_fn;//object is either base class or derived class object
p->member_fn;//p is either base class or derived class pointer
Run Code Online (Sandbox Code Playgroud)

编辑:

#include <iostream>
using namespace std;
class Base
{
       public:
          Base(){ cout<<"Constructor: Base"<<endl;}
          ~Base(){ cout<<"Destructor : Base"<<endl;}
};
class Derived: public Base
{
     //Doing a lot of jobs by extending the functionality
       public:
           Derived(){ cout<<"Constructor: Derived"<<endl;}
           ~Derived(){ cout<<"Destructor : Derived"<<endl;}
 };
void foo()
{
    Base & Var = Derived();
    Base*pVar = new Derived;
    delete pVar;
}
void main()
{
    foo();
        std::cin.get(); …
Run Code Online (Sandbox Code Playgroud)

c++ polymorphism binding runtime compile-time

2
推荐指数
1
解决办法
1027
查看次数

标签 统计

binding ×1

c++ ×1

compile-time ×1

polymorphism ×1

runtime ×1