Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are reference qualifiers for functions? [duplicate]

Tags:

c++

c++11

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 &&?

like image 314
Hector Avatar asked Mar 15 '23 14:03

Hector


1 Answers

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.

like image 101
Yakk - Adam Nevraumont Avatar answered Mar 24 '23 00:03

Yakk - Adam Nevraumont