No member named 'size' in namespace 'std'

僤鯓⒐⒋嵵緔 提交于 2021-01-27 13:16:27

问题


I'm trying to port some C++ code from Windows to OS X (using Xcode).

The following code:

writePosition %= std::size(bufferL);

is generating an error:

No member named 'size' in namespace 'std'

How do I fix this?


回答1:


std::size() is available starting from C++17. Try enabling -std=c++17 for your compiler.

Also, double check that the source files contain #include <iterator>, either directly, or indirectly by #include'ing any of the following headers:

  • <array>
  • <deque>
  • <forward_list>
  • <list>
  • <map>
  • <regex>
  • <set>
  • <string>
  • <string_view>
  • <unordered_map>
  • <unordered_set>
  • <vector>



回答2:


Taking the info from cppreference i see that std::size accepts two kinds of parameters: containers that have a method called size() (from the stl or user defined) and fixed size arrays.

You should check if bufferL is one of these.

Also you have to include the iterator header file if bufferL is a fixed size array and you haven't included any headers containing containers from the stl.




回答3:


To be able to use std::size you would have to ensure to include #include <iterator>. The other thing you would have to check is the compiler supports C++17. This functionality is only available for compiler which are compliant with C++17 standard.

Change the compiler setting in your IDE to C++17 supported compiler.



来源:https://stackoverflow.com/questions/51531258/no-member-named-size-in-namespace-std

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