4

According to this webpage, a non-static member function can have a trailing & or && in its declaration. They have the following example

struct S {
    virtual int f(char) const, g(int) &&; // declares two non-static member functions
    };

1) Does the signature of the second function include the virtual?

virtual int g(int) &&

2) What is the meaning of the trailing &&?

2
  • 2
    Please create two different questions for the two different questions in your text. Jun 26, 2015 at 17:52
  • 1
    && is for the r-value reference for '*this'.
    – Jarod42
    Jun 26, 2015 at 17:54

1 Answer 1

7
struct S {
  virtual int f(char) const, g(int) &&;
};

struct D : S {
  virtual int f(char) const override;
  virtual int g(int) && override;
};

the above code compiles in both g++ and clang. This indicates, at least in practice, that g is virtual in S.

See What is "rvalue reference for *this"? for your other question.

1
  • 2
    Good use of override there! I was going to confirm by testing if a pointer-to-base would call the correct g, but this is much better!
    – Alejandro
    Jun 26, 2015 at 18:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.