2013-08-27 1 views

답변

0

과부하가 아니라 오버라이드에 대해 이야기하고 있다고 생각합니다. 함수에 대한 자격을 갖춘 호출은 다이나믹 디스패치 메커니즘을 사용하지 않습니다 당신이 선택하는 우선 무엇을 제어 할 수 있습니다 : 당신이 정말로 과부하에 대해 이야기하는 경우

struct base { 
    virtual void foo() {...} 
}; 
struct derived : base { 
    virtual void foo() { 
     base::foo();   // call the override at 'base' level 
     ... 
    } 
}; 

, 당신은, 동일한 메커니즘을 사용하거나를 가져올 수 파생 형식의 범위로 오버로드됩니다.

struct base { 
    void foo(int); 
}; 
struct derived : base { 
    using base::foo;   // make all overloads of base::foo available here 
    void foo(double); 
    void f() { base::foo(1); } // alternatively qualify the function call 
}; 
0

super :: foo를 사용할 수 있습니다. 예 :

#include <stdio.h> 

class A 
{ 
public: 
    void foo(void) 
    { 
     printf("Class A\n"); 
    } 
}; 

class B : public A 
{ 
public: 
    void foo(void) 
    { 
     printf("Class B\n"); 
     A::foo(); 
    } 
}; 

int main() 
{ 
    B b; 
    b.foo(); 
} 
1

상속을 활용할 수 있습니다!

class A 
{ 
public: 
    virtual void Foo() 
    { 
     // do some base class foo-ing 
    } 
}; 

class B : public A 
{ 
public: 
    virtual void Foo() 
    { 
     // do some subclass foo-ing 

     // to call the super-class foo: 
     A::Foo(); 
    } 
}; 

void main() 
{ 
    B obj; 
    obj.Foo(); 

    // This is if you want to call the base class Foo directly using the instance obj 
    A* handle = &obj; 
    handle->Foo(); 
} 
나는 단순히와 관계있는 foo는을 실행할 수 없도록하려면
+0

, 나는 슈퍼를 실행하려면, 다음 내 게시물을 업데이트 하위 클래스 – user2673108

+0

다른 물건이 방법의 기본 수준의 호출을 포함하는 이것은 당신이 묘사하고있는 것을 정확하게 할 수있게 해줍니다. 희망이 도움이! –

관련 문제