2014-02-07 2 views
0

이 궁금 언어 기능 또는 컴파일러의 버그 :이상한 그림자는 4.7.2

#include <iostream> 

template<class T> 
class A{ 
public: 

    virtual void func(T const & x) 
    { std::cout << "A func: " << x << "\n"; } 

    void func(T const &x, T const & y) 
    { std::cout << "Double func:\n"; 
    func(x); func(y); 
    } 
}; 

template<class T> 
class B : public A<T>{ 
public: 

    virtual void func(T const & x) 
    { std::cout << "B func: " << x << "\n"; } 
}; 

int main(){ 
    A<int> a; 
    a.func(1); 
    a.func(2,3); 
    B<int> b; 
    b.func(1); 
    b.func(2,3); 
} 

두 a.func (1) 및 a.func (2,3)가 제대로 작동합니다. 그러나 b.func (2,3)이 생성

그것은 그림자 호출되지 것
3.c++: In function ‘int main()’: 
3.c++:27:13: error: no matching function for call to ‘B<int>::func(int, int)’ 
3.c++:27:13: note: candidate is: 
3.c++:20:16: note: void B<T>::func(const T&) [with T = int] 
3.c++:20:16: note: candidate expects 1 argument, 2 provided 

답변

1

하지만 를 숨기고, 그리고 예, 그것은 언어 기능입니다.

template<class T> 
class B : public A<T>{ 
public: 
    using A<T>::func; // <---------------- 
    virtual void func(T const & x) 
     { std::cout << "B func: " << x << "\n"; } 
}; 
:

당신은 using 지침과 기본 기능을 사용할 수 있습니다

관련 문제