简体   繁体   English

命名空间'std'中没有名为'size'的成员

[英]No member named 'size' in namespace 'std'

I'm trying to port some C++ code from Windows to OS X (using Xcode). 我正在尝试将一些C ++代码从Windows移植到OS X(使用Xcode)。

The following code: 以下代码:

writePosition %= std::size(bufferL);

is generating an error: 正在生成错误:

No member named 'size' in namespace 'std' 命名空间'std'中没有名为'size'的成员

How do I fix this? 我该如何解决?

std::size() is available starting from C++17 . std::size() 从C ++ 17开始可用。 Try enabling -std=c++17 for your compiler. 尝试为编译器启用-std=c++17

Also, double check that the source files contain #include <iterator> , either directly, or indirectly by #include 'ing any of the following headers: 另外,请直接或通过#include以下任何标头间接检查源文件是否包含#include <iterator>

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

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. 从cppreference获取信息,我看到std::size接受两种参数:具有名为size() (来自stl或用户定义)和固定大小数组的方法的容器。

You should check if bufferL is one of these. 您应该检查bufferL是否是其中之一。

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. 如果bufferL是一个固定大小的数组,并且你没有包含任何包含stl容器的头文件,你还必须包含iterator头文件。

To be able to use std::size you would have to ensure to include #include <iterator> . 为了能够使用std::size您必须确保包含#include <iterator> The other thing you would have to check is the compiler supports C++17. 您需要检查的另一件事是编译器支持C ++ 17。 This functionality is only available for compiler which are compliant with C++17 standard. 此功能仅适用于符合C ++ 17标准的编译器。

Change the compiler setting in your IDE to C++17 supported compiler. 将IDE中的编译器设置更改为支持C ++ 17的编译器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM