Qualifiers on =delete methods

Viewed 50

When marking special methods as =delete do the qualifiers of the method come into play ? In other words are:

inline constexpr myClass(const myClass&) noexcept = delete;

and

myClass(const myClass&) = delete;

equivalent ?

1 Answers

As often it is, it's usually to just try it and ask the compiler:

class myClass {
    inline constexpr myClass(const myClass&) noexcept = delete;
    myClass(const myClass&) = delete;
};

int main() {
    return 0;
}


1 bla.cpp|4 col 5 error| ‘myClass::myClass(const myClass&)’ cannot be overloaded with ‘constexpr myClass::myClass(const myClass&)’
2 bla.cpp|3 col 22 error| note: previous declaration ‘constexpr myClass::myClass(const myClass&)

So yes, they are the same function. You can try

myClass x;
auto y = x;

with each to ensure the copy constructor was removed. This should make sense - the qualifiers are not a new declaration, they just qualify an existing one.

Related