#include <iostream>
using namespace std;
class A
{
private:
float data_member;
public:
A(int a);
explicit A(float d);
};
A::A(int a)
{
data_member = a;
}
A::A(float d)
{
data_member = d;
}
void Test(A a)
{
cout<<"Do nothing"<<endl;
}
int main()
{
Test(12);
Test(12.6); //Expecting a compile time error here
return 0;
}
この場合、float 値を取る CTOR が明示的であるため、エラーが発生することが予想されます。しかし、VS 2010 ではエラーが発生しません。C++ のキーワード「EXPLICIT」の理解が間違っている場合は、指摘してください。