1

Sorry if it is a duplicated or a silly question.

But i can't compile the following c++ code; (VS2017 Update 15.7.5)

class IInterface
{
public:
  virtual void FnX(int) = 0;
  virtual void FnX(int, int) = 0;
  virtual void FnY(int) = 0;
};

class CClassBase : public IInterface
{
public:
  virtual void FnX(int) override {}
  virtual void FnX(int, int) override final {}
  virtual void FnY(int) override final {}
};

class CClassX : public CClassBase
{
public:
  virtual void FnX(int) override {}
};

void Foo()
{
  CClassX x;
  x.FnY(1);
  x.FnX(2);
  static_cast<CClassBase &>(x).FnX(3, 4);
  static_cast<IInterface &>(x).FnX(5, 6);
  x.FnX(7, 8);
}

Last line x.FnX(7, 8); Doesn't compile. Compile error:

error C2660: 'CClassX::FnX': function does not take 2 arguments

Can anyone please explain that, why it does not compile? or Why function overloading FnX(int, int) could not found?

  • Out of curiosity, is this some academia-related problem? – Ron Jul 27 '18 at 10:52
  • @Ron no. i was only working on a project. and i see it doesn't compiles, what i wrote. i solved it by casting it to base. – Yusuf R. Karagöz Jul 27 '18 at 10:53
  • 1
    Simpler solution: Use `using CClassBase::FnX;` in `CClassX`. Was writing an answer when you closed this. – md5i Jul 27 '18 at 10:55
  • @md5i Nothing new, that's why it is a dupe. ;) [Why does an overridden function in the derived class hide other overloads of the base class?](//stackoverflow.com/a/1628786) – Baum mit Augen Jul 27 '18 at 10:55
  • @BaummitAugen Thank you it seems that is a duplicate. I didn't know how to search my problem. i will delete my question, after reading other question, and answers – Yusuf R. Karagöz Jul 27 '18 at 10:57
  • 1
    @YusufR.Karagöz You're welcome. Deleting this or not is your call; generally, leaving dupes around as signposts is not harmful. – Baum mit Augen Jul 27 '18 at 10:58

0 Answers0