Error on clang (XCode 5.0.2) with std::functional that has more than three parameter

无人久伴 提交于 2019-12-13 06:21:40

问题


I'm stuck with a problem considering clang's behavior with c++ std::functional implementation. Well first things first: Here is some code that I'm trying to compile under MacOs Mavericks with XCode 5.0.2

#include <functional>
#include <ostream>

typedef std::function< std::ostream& (const void*, std::ostream&, uint32_t&, bool) > my_fancy_functor;

static void doSomething(const my_fancy_functor fcn)
{
   //... do something
}    

This results in a "Semantic Error" that holds the following text:

Implicit instantiation of undefined template 'std::__1::function<std::__1::basic_ostream<char> &(const void *, std::__1::basic_ostream<char> &, unsigned int &, bool *)>'

changing the typedef to a std::function that only gets three parameters will compile just fine

typedef std::function< std::ostream& (const void*, std::ostream&, uint32_t&) > my_fancy_functor;

Has anyone an idea what I'm doing wrong here. The code compiles fine with Visual Studio 2010-2013 as well as with gcc version > 4.7.0

As of now I'm sure it has nothing to do with the std::ostream used inside the functional. Substituting any of the types used inside this example with any other imaginable type will result in just the same error message, which brings me to believing that there could be something wrong with the implementation of the std::functional itself.

Any help or hint which helps me resolving this mess will be much appreciated!


回答1:


Set the C++ Language Dialect to C++11 [-std=c++11] or GNU++11 [-std=gnu++11] in your Build Settings and it's going to compile just fine.



来源:https://stackoverflow.com/questions/20654790/error-on-clang-xcode-5-0-2-with-stdfunctional-that-has-more-than-three-param

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!