我在 Windows 窗体 C++ 项目中实现了以下内容
template<class T> class MyQueue
{
T *m_data;
int m_numElements;
public:
MyQueue() : m_data(NULL), m_numElements(0) { }
..... code .....
};
MyQueue<char> logData; // I need to acces it from Form1.h
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}
我想在 Form1.h 中访问它 下
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e)
{
??? MyQueue<char> logData; // I need to acces it
}
有什么线索吗?
最佳答案
您可以将logdata
声明为静态的。访问原始数据成员通常不被认为是好的做法,因此您可能还想提供一个静态方法来将字符放入队列中。这是有关 C++ 静态成员的教程。
http://www.tutorialspoint.com/cplusplus/cpp_static_members.htm
关于c++ - 如何在 C++ 的 MFC 窗体中访问全局变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33656248/