未声明的标识符:可能是一个非常简单的修复
语言:Visual C++、MFC
我正在尝试创建一个指向我在头文件中声明的 CString 变量的指针数组。一般来说,这就是我正在做的事情:
CString *variableArray[5] = {
&var1
, &var2
, &var3
, &var4
, &var5
};
但是,无论出于何种原因,我不断收到以下错误:
Error 1 error C2065: 'var1' : undeclared identifier 18
Error 2 error C2065: 'var2' : undeclared identifier 19
Error 3 error C2065: 'var3' : undeclared identifier 20
Error 4 error C2065: 'var4' : undeclared identifier 21
Error 5 error C2065: 'var5' : undeclared identifier 22
我不太确定是否收到此错误。据我所知,这是创建指针数组的正确方法。任何帮助都会很棒!
编辑:以下是头文件中的声明:
public:
CString var1;
CString var2;
CString var3;
CString var4;
CString var5;
Language: Visual C++, MFC
I'm attempting to make an array of pointers to CString variables that I have declared in my header file. In general, this is what I'm doing:
CString *variableArray[5] = {
&var1
, &var2
, &var3
, &var4
, &var5
};
For whatever reason, though, I keep getting the following error:
Error 1 error C2065: 'var1' : undeclared identifier 18
Error 2 error C2065: 'var2' : undeclared identifier 19
Error 3 error C2065: 'var3' : undeclared identifier 20
Error 4 error C2065: 'var4' : undeclared identifier 21
Error 5 error C2065: 'var5' : undeclared identifier 22
I'm not quite sure I'm getting this error. To me knowledge, this is the correct way to make an array of pointers. Any help would be awesome!
EDIT: Here are the declarations in the header file:
public:
CString var1;
CString var2;
CString var3;
CString var4;
CString var5;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你在哪里创建“variableArray”?如果它在静态方法中或在类的范围之外,那么您收到该错误的原因就有意义了。
Where do you create "variableArray"? If it's in a static method or outside the scope of the class, it would make sense why you're getting that error.