Tôi đang sử dụng Visual Studio 11 beta và tôi tò mò về một lỗi biên dịch tôi nhận được lưu trữ một đối tượng std :: function trong lớp của tôi.Có C++ 11 std :: function giới hạn số đối số mà một con trỏ hàm có thể có?
typedef std::function<void (int, const char*, int, int, const char*)> MyCallback;
Trong lớp của tôi, tôi có,
MyCallback m_callback;
này biên dịch tốt. Nếu tôi thêm một đối số nữa vào danh sách thì nó không thành công.
typedef std::function<void (int, const char*, int, int, const char*, int)> MyCallback;
Sự thất bại là:
>c:\program files (x86)\microsoft visual studio 11.0\vc\include\functional(535): error C2027: use of undefined type 'std::_Get_function_impl<_Tx>'
1> with
1> [
1> _Tx=void (int,const char *,int,int,const char *,int)
1> ]
1> f:\development\projects\applications\my.h(72) : see reference to class template instantiation 'std::function<_Fty>' being compiled
1> with
1> [
1> _Fty=void (int,const char *,int,int,const char *,int)
1> ]
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\functional(536): error C2504: 'type' : base class undefined
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\functional(539): error C2027: use of undefined type 'std::_Get_function_impl<_Tx>'
1> with
1> [
1> _Tx=void (int,const char *,int,int,const char *,int)
1> ]
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\functional(539): error C2146: syntax error : missing ';' before identifier '_Mybase'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\functional(539): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Đây là một thư viện liên kết động mà đang chuẩn bị dữ liệu để chuyển cho ứng dụng khác. Tôi chắc chắn có thể làm lại định dạng của dữ liệu để nó có thể được thông qua với ít đối số hơn, nhưng tôi đã tự hỏi tại sao tôi thấy giới hạn này?
Switching trở lại c kiểu con trỏ hàm,
typedef void (*MyCallback)(int, const char*, int, int, const char*, int);
dường như làm việc tốt.
Câu trả lời đúng. Ngoài ra, hãy xem [Magic && Secrets] (http://channel9.msdn.com/Events/GoingNative/GoingNative-2012/STL11-Magic-Secrets) của STL tại GoingNative 2012, anh ấy đề cập đến điều này một hoặc hai lần. – Xeo
Điều thú vị. Tôi nhớ việc triển khai các mẫu variadic chỉ là một nỗ lực nhỏ trên phía g ++ của mọi thứ. –
Tuyệt vời, câu trả lời cho câu hỏi của tôi, Cảm ơn! – BZor