什么是“表达式必须具有类类型"?错误是什么意思? [英] What does "expression must have class type" error mean?
本文介绍了什么是“表达式必须具有类类型"?错误是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#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
}
}
在这里我在做什么错,因为该计划只是用一些数字填充数组
What am I doing wrong here becuase the plan is to just fill the array with some numbers
推荐答案
执行以下操作:
int arrayTest[512];
int size = sizeof(arrayTest)/sizeof(*arrayTest);
C样式的数组没有成员函数.他们没有阶级的概念.
C-style arrays don't have member function. They don't have any notion of class.
无论如何,更好使用std::array
:
#include <array>
std::array<int,512> arrayTest;
int size = arrayTest.size(); //this line is exactly same as you wrote!
看起来像您想要的.现在,您可以使用索引i
作为arrayTest[i]
来访问arrayTest
的元素,其中i
的范围可以从0
到size-1
(包括).
which looks like what you wanted. Now you can use index i
to access elements of arrayTest
as arrayTest[i]
where i
can vary from 0
to size-1
(inclusive).
这篇关于什么是“表达式必须具有类类型"?错误是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文