[操作疑难] C++ 呢句嘢应该点写法 ?

本帖最后由 ghostkcleung 于 2021-5-19 01:00 编辑

class Base {
  public:
  virtual void func ( ) { }

  protected:

  void a(int x) {
    a(x, 0);
  }

  virtual void a(int x, int y) = 0;
} ;

class Dervied: public Base {
  public:
  void func ( ) {
    a ( 1 ) ;  // no matching function for call to 'Dervied::a(int)'
    // 明明个 Method 承继咗架喎。

  }

  protected:
  void a(int x, int y) { }
} ;

Base 个 a(int x, int y) 有两个 arguments, function signature 错咗

TOP

但我一样系 overload 咗 a(int x)
既然呢啲问题系无得解,
最后我系改 method name

Base 个 a(int x, int y) 有两个 arguments, function signature 错咗
rkkc 发表于 2021-5-19 01:22

TOP

a(int x), a(int x, int y) argument 多咗但相同 type , overload 唔到

唔同 type 例: a(double x) 就可以 overload

TOP

https://en.cppreference.com/w/cpp/language/unqualified_lookup
https://en.wikipedia.org/wiki/Dominance_(C%2B%2B)
大概嘅情况就系 Derived::a(int, int) 会遮住 Base::a 所有name lookup
重要分C++11之前同之后两种做法...
如果无Google查可能就变"鬼故"

TOP