Considering the code below:
#include <iostream>
class tester
{
public:
tester(){}
explicit tester(double val) :
m_a(val) // I assume this now overwrites the "default" initialise value?
{}
double m_a {1.123}; // Default constructor value?
};
int main()
{
tester t1;
tester t2(2.456);
std::cout << "t1:" << t1.m_a << std::endl;
std::cout << "t2:" << t2.m_a << std::endl;
return 0;
}
My question is, can you have both the initialise value in the class and in the constructor body? - how does the compiler resolve this? It appears that the constructor wins since the output of this program is:
t1:1.123
t2:2.456