Mar*_*ant 4 c++ templates visual-c++-2008 visual-c++ visual-c++-2010
在Visual C++(2008和2010)中,以下代码无法编译,并出现以下错误:
#include <memory>
void Foo( std::shared_ptr< int > test = ::std::make_shared< int >( 5 ) )
{
}
class P
{
void
Foo( std::shared_ptr< int > test = ::std::make_shared< int >( 5 ) )
{
}
};
Run Code Online (Sandbox Code Playgroud)
错误C2039:'make_shared':不是'`global namespace''的成员
错误C3861:'make_shared':找不到标识符
它抱怨P :: Foo()的定义不是:: Foo().
有人知道为什么Foo()有一个与std :: make_shared但不是P :: Foo()的默认参数有效吗?
它看起来像编译器中的一个错误.以下是重现问题所需的最少代码:
namespace ns
{
template <typename T>
class test
{
};
template <typename T>
test<T> func()
{
return test<T>();
}
}
// Works:
void f(ns::test<int> = ns::func<int>()) { }
class test2
{
// Doesn't work:
void g(ns::test<int> = ns::func<int>())
{
}
};
Run Code Online (Sandbox Code Playgroud)
Visual C++ 2008和2010都报告:
错误C2783:'
ns::test<T> ns::func(void)':无法推断'T'的模板参数
Comeau对此代码没有任何问题.
| 归档时间: |
|
| 查看次数: |
4106 次 |
| 最近记录: |