简体   繁体   中英

HP-UX C/aC++ compiler bug with using-statements for pure virtual methods

I'm trying to build this legitimate C++ code in HP-UX 11.11, using HP C/aC++ compiler version A.03.85:

class BaseClass
{
public:

  virtual int sum(int i) = 0;
};

class Derived : public BaseClass
{
public:

  using BaseClass::sum;
  virtual int sum(int i1, int i2) = 0;
};

class Impl : public Derived
{
public:
  virtual int sum(int i) { return i+1; }
  virtual int sum(int i1, int i2) { return i1+i2; }
};

int main()
{
  Derived * obj = new Impl;
  obj->sum(5);
  delete obj;
}

However it fails with the following compilation error:

Error 181: "test_using.cpp", line 26 # Expected 2 argument(s) for "int Derived::sum(int,int)"; had 1 instead.
      obj->sum(5);
      ^^^^^^^^^^^

I'm able to build exactly this same code in other platforms such as Linux, AIX and Windows without any issues. The problem for HP seems to be related with pure virtual methods, because if I remove the "= 0" snippet from "BaseClass" then everything works as expected.

So, my question is: Have you guys faced a similar issue before? How did you work around it? is this a know aC++ bug?

Please note that I CANNOT turn the pure virtual methods into regular ones.

class Derived : public BaseClass
{
public:
    virtual int sum(int i) = 0;
    virtual int sum(int i1, int i2) = 0;
};

Or if you want to better document why you made the change and what the code should be:

class Derived : public BaseClass
{
public:

# ifdef USING_HP_BUGWARE
    virtual int sum(int i) = 0;
# else
    using BaseClass::sum;
# endif

    virtual int sum(int i1, int i2) = 0;
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM