Consider the following code with one variable default constructed and the other one value constructed:
#include <iostream>
#include <typeinfo>
struct A
{
A() : m_() {}
A(int m) : m_(m) {}
int m_;
};
int main()
{
A a, b(), c(5);
std::cout << typeid(a).name() << std::endl;
std::cout << typeid(b).name() << std::endl;
std::cout << typeid(c).name() << std::endl;
return 0;
}
With GCC 4.8 the output is
A
A ()
A
So a,c
and b
have different types although they refer to the same struct/class. How can this be?
(Of course, this is a minimal example derived from an issue of a complex code. There, I get something like A
vs. A(int)
but I can't reproduce this yet.)
The declaration
A b()
means thatb
is a function of signatureA ()
, notwithstanding the fact it is mixed with declarations of variablesa
andc
of typeA
. The following modifications to the example code make it clearer:The output is
So
a
andb
are default and value constructed, resp., butc
is a function declaration and thus of different type.