Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 空向量的全局向量_C++_Class_Vector - Fatal编程技术网

C++ 空向量的全局向量

C++ 空向量的全局向量,c++,class,vector,C++,Class,Vector,我有一个有两个全局向量的类。一个是结构向量,另一个是结构向量。是这样的: class CNewDisplay: { protected: //Vector of structures struct FP { .... } std::vector<FP> FP_list; //Vector of vectors of structures struct INSTRUCTIONS {... } std::vector<INSTRUCTIONS> Instruction_

我有一个有两个全局向量的类。一个是结构向量,另一个是结构向量。是这样的:

class CNewDisplay:
{
protected:

//Vector of structures
struct FP
{
....
}
std::vector<FP> FP_list;

//Vector of vectors of structures
struct INSTRUCTIONS
{...
}

std::vector<INSTRUCTIONS> Instruction_list;
std::vector< std::vector<INSTRUCTIONS> > Past_Instructions;

public:
    std::string loop_planes(..)
    void fill_instruction_vector(...)
填充
过去的\u指令的函数

void CNewDisplay::fill_instruction_vector(...){
    ....
    Past_Instructions.push_back(Instruction_list);
    Instruction_list.clear();
    //The size of the `Past_Instructions` is correct here
}
py\u embed()
函数退出后,
过去的指令
是空的。我想这与
void py\u embed(void)
不在类公共函数中有关,但我不明白为什么,因为它是
void fill\u指令向量(…)
调用并填充
过去的\u指令
向量,因为
过去的\u指令
是全局的。有人能给我解释一下吗


注意:将向量传递给类的公共成员不起作用。

我不明白为什么您有std::vector,然后只有vector。我已经更正了,谢谢您的帮助advice@40two向量不会传递到
填充指令\u vector()
,而是在函数内部访问。这就是你要问的吗?从表面上看,
指令列表
过去的指令
根本不是全局指令,而是类
CNewDisplay
的成员,具有
受保护的
访问权限。现在在“py_embed()”中,您声明了一个
CNewDisplay
对象(即
dlg
),该对象将位于函数“py_embed()”的本地范围内(即
py_embed()
退出
dlg
后不再存在)。我的问题是,既然
dlg
是“死的”,除了要填充的向量之外,还有什么向量?过去的\u指令应该是来自多个CNewDisplay实例的共享/组合历史吗?如果是这样,您只需要将过去的_指令声明为“static”,并在.cpp文件中实例化它。
void CNewDisplay::fill_instruction_vector(...){
    ....
    Past_Instructions.push_back(Instruction_list);
    Instruction_list.clear();
    //The size of the `Past_Instructions` is correct here
}