问题描述
我在向量
类中发生错误,当您在 #include< vector>
I'm getting an error occurring in the vector
class, as in, the class which you access when you #include < vector >
我只有一次,我没有线索为什么会发生:
I it get only once, and I don't have a clue why it would be occurring:
这也出现在向量中,出现错误的代码如下:
This is also occurring in vector, and the code that has the error is here:
size_type size() const
{ // return length of sequence
return (this->_Mylast - this->_Myfirst); // error on this line
}
推荐答案
这意味着类型 Agent
在此时尚未完全知道。
This mean that the type Agent
is not fully known at this point. You probably just have forward-declared it, but don't have a definition visible at this point.
下面的代码会显示这个错误:
The following piece of code exhibit this error:
#include <vector>
class Agent;
static int getSize(std::vector< Agent > const& v) {
return v.size();
}
你需要的是包含定义 Agent
类,然后使用 std :: vector<代理>
。该文件可能命名为 Agent.h
。
What you need is to include the file that define the Agent
class before you use a std::vector< Agent >
. The file is probably named Agent.h
.
错误的原因是因为在代码行指向,编译器尝试计算两个 Agent const *
之间的差异。这大致等于投射到 char const *
除以 sizeof(Agent)
的指针之差。但是,此大小不知道类型是否未完全定义。
The reason for the error is because in the line of code you pointed, the compiler try to compute the difference between two Agent const*
. This is roughly equal to the difference of the pointer casted to char const*
divided by sizeof(Agent)
. However, this size is not know if the type is not fully defined.
这篇关于错误C2036:'Agent * const':'向量'类中未知的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!