我使用Visual C ++ 2010速成。 我有一个表格( Form1.h
),其中包含一个按钮( btn1
)和标签( label1
)。
当我按一下按钮,我想从一个不同的头文件(调用一个函数testing.h
),那么将进行更改标签的文本。
我所拥有的是这样的事情...
Form1.h
#include "testing.h"
... standard form code generated by Visual Studio
private: System::Windows::Forms::Label^ label1;
...
private: System::Void btn1_Click(System::Object^ sender, System::EventArgs^ e) {
testfunc1();
}
};
其中testing.h是一样的东西...
#ifndef _TESTING_FUNCS
#define _TESTING_FUNCS
void testfunc1(){
label1->Text = "Text has been changed from outside.";
}
#endif
当我尝试编译并运行它,我得到的错误说'label1' is an undeclared identifier
(testing.h内),并参照“错误left of '->Text' must point to class/struct/...
“
我是新的C ++,通常使用Java,所以这里也有一些新的东西给我。 对我来说,有两个明显的选择:
1)传递标签的函数作为参数
2)不知何故从访问标签testing.h
头文件,SANS引用
但我真的不知道该怎么办无论是。