template<class T>
class test
{
public:
test()
{
}
test(T& e)
{
}
};
int main()
{
test<double> d(4.3);
return 0;
}
다음과 같은 오류와 함께 g ++ 4.4.1를 사용하여 컴파일 :C++ 템플릿 : 암시 적 변환, 호출의 ctor하기 위해 일치하는 기능
g++ test.cpp -Wall -o test.exe
test.cpp: In function 'int main()':
test.cpp:18: error: no matching function for call to 'test<double>::test(double)
'
test.cpp:9: note: candidates are: test<T>::test(T&) [with T = double]
test.cpp:5: note: test<T>::test() [with T = double]
test.cpp:3: note: test<double>::test(const test<double>&)
make: *** [test.exe] Error 1
그러나,이 작품 :
double a=1.1;
test<double> d(a);
왜 이게 뭐야? g ++에서 리터럴 표현식 1.1을 암시 적으로 double로 변환 할 수 없습니까? 감사합니다. .
생성자가 double을 사용하지 않으면 double에 대한 참조가 필요합니다. –