- 论坛徽章:
- 0
|
我用C++11的语法,如果尝试下面的代码,编译没有问题:
- shared_ptr<FILE> fp(fopen("d:\\abc.txt", "w"),fclose);
复制代码 但是如果我改成了make_shared函数模板,就会有编译问题
- shared_ptr<FILE> fp = make_shared<FILE>(fopen("d:\\abc.txt", "w"),fclose);
复制代码 到底哪里出了问题,代码应该怎么改? 多谢。
-----------------------------------------
GCC4.8的编译错误是如下:
||=== Build: Debug in m1 (compiler: GNU GCC Compiler) ===|
c:\program files (x86)\codeblocks\mingw\lib\gcc\mingw32\4.8.1\include\c++\ext\new_allocator.h||In instantiation of 'void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = _iobuf; _Args = {_iobuf*, int (__attribute__((__cdecl__)) & (_iobuf*)}; _Tp = _iobuf]'
c:\program files (x86)\codeblocks\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\alloc_traits.h|254|required from 'static typename std::enable_if<std::allocator_traits<_Alloc>::__construct_helper<_Tp, _Args>::value, void>::type std::allocator_traits<_Alloc>::_S_construct(_Alloc&, _Tp*, _Args&& ...) [with _Tp = _iobuf; _Args = {_iobuf*, int (__attribute__((__cdecl__)) & (_iobuf*)}; _Alloc = std::allocator<_iobuf>; typename std::enable_if<std::allocator_traits<_Alloc>::__construct_helper<_Tp, _Args>::value, void>::type = void]'|
c:\program files (x86)\codeblocks\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\alloc_traits.h|393|required from 'static decltype (_S_construct(__a, __p, (forward<_Args> (std::allocator_traits::construct::__args)...)) std::allocator_traits<_Alloc>::construct(_Alloc&, _Tp*, _Args&& ...) [with _Tp = _iobuf; _Args = {_iobuf*, int (__attribute__((__cdecl__)) & (_iobuf*)}; _Alloc = std::allocator<_iobuf>; decltype (_S_construct(__a, __p, (forward<_Args> (std::allocator_traits::construct::__args)...)) = <type error>]'|
c:\program files (x86)\codeblocks\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\shared_ptr_base.h|400|required from 'std::_Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp>::_Sp_counted_ptr_inplace(_Alloc, _Args&& ...) [with _Args = {_iobuf*, int (__attribute__((__cdecl__)) & (_iobuf*)}; _Tp = _iobuf; _Alloc = std::allocator<_iobuf>; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]'|
c:\program files (x86)\codeblocks\mingw\lib\gcc\mingw32\4.8.1\include\c++\ext\new_allocator.h|120|required from 'void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = std::_Sp_counted_ptr_inplace<_iobuf, std::allocator<_iobuf>, (__gnu_cxx::_Lock_policy)2u>; _Args = {const std::allocator<_iobuf>, _iobuf*, int (__attribute__((__cdecl__)) & (_iobuf*)}; _Tp = std::_Sp_counted_ptr_inplace<_iobuf, std::allocator<_iobuf>, (__gnu_cxx::_Lock_policy)2u>]'|
c:\program files (x86)\codeblocks\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\alloc_traits.h|254| [ skipping 2 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]|
c:\program files (x86)\codeblocks\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\shared_ptr_base.h|523|required from 'std::__shared_count<_Lp>::__shared_count(std::_Sp_make_shared_tag, _Tp*, const _Alloc&, _Args&& ...) [with _Tp = _iobuf; _Alloc = std::allocator<_iobuf>; _Args = {_iobuf*, int (__attribute__((__cdecl__)) & (_iobuf*)}; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]'|
c:\program files (x86)\codeblocks\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\shared_ptr_base.h|986|required from 'std::__shared_ptr<_Tp, _Lp>::__shared_ptr(std::_Sp_make_shared_tag, const _Alloc&, _Args&& ...) [with _Alloc = std::allocator<_iobuf>; _Args = {_iobuf*, int (__attribute__((__cdecl__)) & (_iobuf*)}; _Tp = _iobuf; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]'|
c:\program files (x86)\codeblocks\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\shared_ptr.h|316|required from 'std::shared_ptr<_Tp>::shared_ptr(std::_Sp_make_shared_tag, const _Alloc&, _Args&& ...) [with _Alloc = std::allocator<_iobuf>; _Args = {_iobuf*, int (__attribute__((__cdecl__)) & (_iobuf*)}; _Tp = _iobuf]'|
c:\program files (x86)\codeblocks\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\shared_ptr.h|598|required from 'std::shared_ptr<_Tp1> std::allocate_shared(const _Alloc&, _Args&& ...) [with _Tp = _iobuf; _Alloc = std::allocator<_iobuf>; _Args = {_iobuf*, int (__attribute__((__cdecl__)) &)(_iobuf*)}]'|
c:\program files (x86)\codeblocks\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\shared_ptr.h|614|required from 'std::shared_ptr<_Tp1> std::make_shared(_Args&& ...) [with _Tp = _iobuf; _Args = {_iobuf*, int (__attribute__((__cdecl__)) &)(_iobuf*)}]'|
D:\Documents\gccprojects\m1\main.cpp|6|required from here|
c:\program files (x86)\codeblocks\mingw\lib\gcc\mingw32\4.8.1\include\c++\ext\new_allocator.h|120|error: new initializer expression list treated as compound expression [-fpermissive]|
c:\program files (x86)\codeblocks\mingw\lib\gcc\mingw32\4.8.1\include\c++\ext\new_allocator.h|120|error: no matching function for call to '_iobuf::_iobuf(int (__attribute__((__cdecl__)) &)(_iobuf*))'|
c:\program files (x86)\codeblocks\mingw\lib\gcc\mingw32\4.8.1\include\c++\ext\new_allocator.h|120|note: candidates are
c:\program files (x86)\codeblocks\mingw\include\stdio.h|129|note: _iobuf::_iobuf()|
c:\program files (x86)\codeblocks\mingw\include\stdio.h|129|note: candidate expects 0 arguments, 1 provided|
c:\program files (x86)\codeblocks\mingw\include\stdio.h|129|note: constexpr _iobuf::_iobuf(const _iobuf&)|
c:\program files (x86)\codeblocks\mingw\include\stdio.h|129|note: no known conversion for argument 1 from 'int(_iobuf*)' to 'const _iobuf&'|
c:\program files (x86)\codeblocks\mingw\include\stdio.h|129|note: constexpr _iobuf::_iobuf(_iobuf&&)|
c:\program files (x86)\codeblocks\mingw\include\stdio.h|129|note: no known conversion for argument 1 from 'int(_iobuf*)' to '_iobuf&&'|
||=== Build failed: 3 error(s), 11 warning(s) (0 minute(s), 0 second(s)) ===| |
|