Possible Duplicate:
Does std::function's copy-constructor require the template type's argument types to be complete types?
I have a simple class with a callback built on std::function, but it's not building with C++11 / libc++. I think I see the error, but I don't know the solution.
#include <functional>
struct Base {
typedef std::function<void( Base baseInstance )> Callback;
Base() {}
virtual ~Base() {}
void setCallBack( Callback callback ) { mCallback = callback; }
private:
Callback mCallback; // <--- Error, "Ivalid application of 'sizeof' to an incomplete type of 'Base'"
};
full error log:
In file included from /Volumes/ssd/code/sandbox/test_touchtracker_libcpp/test_touchtracker_libcpp/main.cpp:9:
In file included from /Applications/Xcode45-DP2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/iostream:38:
In file included from /Applications/Xcode45-DP2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ios:216:
In file included from /Applications/Xcode45-DP2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/__locale:15:
In file included from /Applications/Xcode45-DP2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/string:434:
In file included from /Applications/Xcode45-DP2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/algorithm:591:
/Applications/Xcode45-DP2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/type_traits:2825:19: error: invalid application of 'sizeof' to an incomplete type 'Base'
static_assert(sizeof(_Tp) > 0, "Type must be complete.");
^~~~~~~~~~~
/Applications/Xcode45-DP2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/type_traits:2812:15: note: in instantiation of template class 'std::__1::__check_complete<Base>' requested here
private __check_complete<_T0, _Tp...>
^
/Applications/Xcode45-DP2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/type_traits:2978:15: note: in instantiation of template class 'std::__1::__check_complete<std::__1::function<void (Base)> &, Base>' requested here
: private __check_complete<_Fp, _Args...>
^
/Applications/Xcode45-DP2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/type_traits:2989:11: note: in instantiation of template class 'std::__1::__invokable_imp<std::__1::function<void (Base)> &, Base>' requested here
__invokable_imp<_Fp, _Args...>::value>
^
/Applications/Xcode45-DP2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/functional:1115:33: note: in instantiation of template class 'std::__1::__invokable<std::__1::function<void (Base)> &, Base>' requested here
template <class _Fp, bool = __invokable<_Fp&, _ArgTypes...>::value>
^
/Applications/Xcode45-DP2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/functional:1163:9: note: in instantiation of default argument for '__callable<std::__1::function<void (Base)> >' required here
__callable<typename decay<_Fp>::type>::value,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode45-DP2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/functional:1166:7: note: while substituting deduced template arguments into function template 'operator=' [with _Fp = const std::__1::function<void (Base)> &]
operator=(_Fp&&);
^
/Volumes/ssd/code/sandbox/test_touchtracker_libcpp/TouchTracker.h:5:8: note: definition of 'Base' is not complete until the closing '}'
struct Base {
^
1 error generated.
So, the std::function is not complete. But I want this class to be able to take a reference to a callback, to this class. So I'm in a bit of a pickle. Anyone know how to handle this with C++11?
Note: this code compiles without a problem when using <tr1/functional>