I know constructor do not have a return type. Though I wonder, what is the type of a constructor then? Does a constructor have a type?
I tried this
struct A { A() {} };
template <typename A> struct foo;
int main() { foo< decltype(&A::A) > f; }
to get the error (gcc)
prog.cc: In function 'int main()':
prog.cc:5:32: error: taking address of constructor 'constexpr A::A(A&&)'
5 | int main() { foo< decltype(&A::A) > f; }
| ^
prog.cc:5:35: error: template argument 1 is invalid
5 | int main() { foo< decltype(&A::A) > f; }
| ^
...well, ok I cannot take the address. Also this fails:
int main() { foo< decltype(A::A) > f; }
with
prog.cc: In function 'int main()':
prog.cc:5:32: error: decltype cannot resolve address of overloaded function
5 | int main() { foo< decltype(A::A) > f; }
| ^
[...]
which is probably just a very confusing error message caused by the same reason as above (cannot take adress of constructor) and I dont know what else to try..
What is the type of a constructor?
If it has no type, then what is it? Certainly it is not A (member_function)()
.
PS: To clarify what is my confusion: cpprefernce states
Constructor is a special non-static member function of a class that is used to initialize objects of its class type.
And my logic goes like this: Member function have a type, constructors are special kinds of member functions, hence they should have a type. I know the reasoning is flawed, but why?