Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/146.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ c+时出现错误LNK2005+;在vs2012中,lambdas与/Yu标志一起使用_C++_Visual Studio 2012_C++11_Precompiled - Fatal编程技术网

C++ c+时出现错误LNK2005+;在vs2012中,lambdas与/Yu标志一起使用

C++ c+时出现错误LNK2005+;在vs2012中,lambdas与/Yu标志一起使用,c++,visual-studio-2012,c++11,precompiled,C++,Visual Studio 2012,C++11,Precompiled,在我的一个实用程序头文件中有以下函数 template<typename T> static void rtrim(std::basic_string<T, std::char_traits<T>, std::allocator<T>> &t) { t.erase(find_if(t.rbegin(), t.rend(), [](T& c)->bool{ return !isspa

在我的一个实用程序头文件中有以下函数

template<typename T>
static void rtrim(std::basic_string<T, std::char_traits<T>, std::allocator<T>> &t) 
{ 
      t.erase(find_if(t.rbegin(), t.rend(), 
              [](T& c)->bool{ return !isspace(c); }).base(), t.end());
} 
模板
静态无效rtrim(标准::基本字符串和t)
{ 
t、 擦除(如果(t.rbegin(),t.rend(),则查找),
[](T&c)->bool{return!isspace(c);}.base(),T.end();
} 
我正在使用Visual Studio 2012在(/Yu)上构建带有预编译头的代码。生成失败,出现以下错误

1> stdafx.obj:错误LNK2005:“public:void\uu cdecl ::运算符()(类 std::基本_字符串,类 std::分配器>常量&)常量“ (?@R@@QEBAXAEBV?$basic)_string@_WU?$char_traits@_W@性病病毒$allocator@_W@2@@@std@@@Z) 已在中定义


如果我删除
/Yu
标志,它就可以正常构建。这是否意味着lambdas不能与预编译头一起使用?附近有工作吗

不要使用
静态void rtrim(…)
尝试
内联void rtrim(…)
。如果(t.rbegin(),t.rend(),::isspace)内联不起作用,那么另一种选择是去掉lambda-
find_。我的代码充满了模板。我想用C++ LAMDAS简化模板代码。这是我正在尝试的一个简单的例子。我的代码以前没有使用LAMDAS,它看起来和您所说的完全一样。我注意到只有当本地C++ 11库链接到托管C++应用程序时才会发生。我的意思是,在管理C++应用程序中出现了生成错误。@ PARTEORIAN:模板函数已经是代码>内联< /代码>——嗯,不是严格的说,但实际上,<代码>内联赋予函数的属性已经是函数模板的属性。