The return type of remote functions in C ++ 11

In C ++ 11, we can disable the constructor and assignment operator, with delete:

class A {
  A(const A&) = delete;
  A& operator=(const A&) = delete;
}

One day, my colleague uses a void return type, not a link.

class A {
  A(const A&) = delete;
  void operator=(const A&) = delete;
}

Is that okay too?

for example if i have

A a, b, c;
a = b = c;

will it work?

+4
source share
3 answers

The return types are not part of the function signature in C ++ (therefore, you cannot overload functions with just the return type). So this is normal, because your remote function will still be found while searching for the name. Perhaps you may have compiler warnings, depending on your version / compiler settings.

+2

operator= . *this void . int* std::string. .

, , , , , , .

void, . a=b=c ; " void" .

+2

the compiler infers the return type from the selected overload. If the overload is explicitly removed, compilation fails before the return type is taken into account.

0
source

Source: https://habr.com/ru/post/1668715/


All Articles