C++ : how to access an object created in Form1?
i am new in C++, i'm using VC++ 2008, i have created a form with pictureBox inside with gui design, located in Form1.h.
for code stability, i'm trying to separate beetween gui and processing classes, so i made a new class in process.h which contain code to change image in the pictureBox, the problem is that i cant access pictureBox object from process.h because it's located in different class.
note : the classname of form is Form1 inside namespace try, the classname of process is processImage
i have tried to make a setter function named setImage() in class Form1 to set image path of imageBox obj, but i cant make object of Form1 to call that function because Form1 class is not known. for note i have tried to #include "Form1.h" but it still unknown.
is there any solut开发者_运维知识库ion for my problem?
thanks for your help..
Create the class ProcessImage and make an object of this class a member variable of the Form1 class. Create a setImage public method in the ProcessImage class. Whenever the image in the picture box is updated, call this method.
I'm not sure if I could understand your problem, but here's few hints.
You say that you include Form1.h but Form1 is still not visible. It could be the problem when A include B and B include A, that could be solved with forward declarations. Make sure that you don't forget the namespaces.
A.h:
#include "B.h"
namespace NamespaceB
{
class B; // forward declaration
}
namespace NamespaceA
{
class A
{
NamespaceB::B m_pB;
};
}
B.h:
#include "A.h"
namespace NamespaceA
{
class A; // forward declaration
}
namespace NamespaceB
{
class B
{
NamespaceA::A* m_pA;
};
}
精彩评论