2

このコードを考えてみましょう:

struct message
{
  uint8_t* data;
  size_t length;
};

class device_base
{
  // ...
public:
  virtual ssize_t exec(uint8_t cmd, const uint8_t* data = nullptr, size_t length = 0);
  inline ssize_t exec(uint8_t cmd, const message& msg)
  {
    return exec(cmd, msg.data, msg.length);
  }
  // ...
};

class device : public device_base
{
  // The exec method do not overloaded or overridden here.
};

class device_uart : public device
{
  // ...
public:
  ssize_t exec(uint8_t cmd, const uint8_t* data = nullptr, size_t length = 0);
  void some_method(const message&);
  // ...
};

// ...

void device_uart::some_method(const message& msg)
{
  // exec(SOME_COMMAND, msg); // The inline method device_base::exec is invisible here by some reason.
  device::exec(SOME_COMMAND, msg); // OK.
  device_base::exec(SOME_COMMAND, msg); // OK too.
  exec(SOME_COMMAND, msg.data, msg.length); // OK, of course.
}

インラインの非仮想メソッドがクラスexecに表示されないのはなぜですか?device_uart

4

1 に答える 1