0

私たちの教科書の1つでは、優れた設計手法としてC++のインターフェイスを使用することが提案されています。以下に例を示します。

class IAnimation
{
  public:
      virtual void VAdvance(const int deltaMilisec) = 0;
      virtual bool const VAtEnd() const = 0;
      virtual int const VGetPostition() const = 0;
};

私は次の意味を理解していませんでした:

virtual bool const VAtEnd() const = 0;
virtual int const VGetPostition() const = 0;

constは、constインスタンスから呼び出し可能にするために()の後に使用されることを知っています。しかし、VAtEndとVGetPosition(メソッド名)の前のconstはどういう意味ですか?

ありがとうございました。

4

1 に答える 1

7

これは、戻りタイプがconstであることを意味し、次と同じです。

virtual const bool VAtEnd() const = 0;
virtual const int VGetPostition() const = 0;

とにかく戻り値がコピーされるので、それは実際的な意味はありません。

ただし、オブジェクトを返す場合:

struct A
{
    void goo() {}
};

const A foo() {return A();}



int main()
{
    A x = foo();
    x.goo();      //ok
    foo().goo();  //error
}
于 2012-04-16T16:23:47.157 に答える