I have defined globally a list in one class as a pointer:
class1.cpp
type list[1000];
type *p_list = list;
Now I want to use this list and put some values into it. This should happen in another class, in a method
class2.cpp
mousePressEvent_from_class_2()
{
p_list[counter].x = pos().x();
}
But the compiler is telling me that it doesn’t know p_list. How can I change that?
The compiler needs to know that
p_listis declared elsewhere. Put the following inclass1.hor inclass2.cpp(at file scope).The definition of
typemust also be visible inclass2.cpp. Make sure the definition is in a header file (class1.h) and class2.cpp#includes this header.