我有一个包含向量的类,它还继承了另一个类:
class txtExt : public extention
{
private:
string openedFile_;
public:
vector<string> txtVector; //the vector i want to call
};
我将向量填充到类中的方法中:
class Manager : public extention
{
// there is some other code here that I know does work
// and it calls this function:
void organizeExtention(string filename, string ext)
{
if(ext == "txt")
{
txtExt txtExt;
txtExt.txtVector.pushback(filename);
}
}
}
这是我尝试调用向量的主要课程:
int main()
{
// some code here that does previous operations like getting the path
// and filling the vector
// I've tried many ways of trying to call the vector
// here is an example of one:
vector<txtExt*> testVector;
for(int i = 0; i < testVector.size(); ++i)
{
cout << testVector[i] << endl;
}
return 0;
}
我有几个问题:
- 我把向量叫错了吗?
- 我的向量是空的吗?
- 我是否必须使我的向量全局化,以便其他类可以看到它?
注意:我已经能够使用非常简单的 for 循环打印出加载向量的向量