#include <cstdlib>
using namespace std;
int main()
{
int arrayTest[512];
int size = arrayTest.size();
for(int a = 0;a<size;a++)
{
//stuff will go here
}
}
我在这里做错了什么,因为计划只是用一些数字填充数组
最佳答案
这样做:
int arrayTest[512];
int size = sizeof(arrayTest)/sizeof(*arrayTest);
C 风格数组没有成员函数。他们没有任何类(Class)观念。
无论如何,更好使用std::array
:
#include <array>
std::array<int,512> arrayTest;
int size = arrayTest.size(); //this line is exactly same as you wrote!
这看起来像你想要的。现在您可以使用索引 i
访问 arrayTest
的元素作为 arrayTest[i]
其中 i
可以不同于 0
到 size-1
(含)。
关于c++ - "expression must have class type"错误是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18965212/