C++0x有没有(或者C++0x在某个时候会有)构造函数的模板参数推演?在An Overview of the Coming C++ (C++0x) Standard中,我看到了以下几行:
std::lock_guard l(m); // at 7:00
std::thread t(f); // at 9:00这是否意味着委派make_foo函数模板最终是多余的?
发布于 2011-08-07 17:38:05
模板参数推导适用于任何函数,包括构造函数。但是您不能从传递给构造函数的参数中推断出类模板参数。不,你也不能在C++0x中这样做。
struct X
{
template <class T> X(T x) {}
};
template <class T>
struct Y
{
Y(T y) {}
};
int main()
{
X x(3); //T is deduced to be int. OK in C++03 and C++0x;
Y y(3); //compiler error: missing template argument list. Error in 03 and 0x
}lock_guard和thread不是类模板。不过,他们有构造函数模板。
https://stackoverflow.com/questions/6971904
复制相似问题