I have a reusable header which is consumed by multiple components. I introduced a member function and a member variable to the outer class and called it from one component. The implementation of the function was done in the .cpp of the reusable header. It was built successfully but while performing the workflow and opening the component, it could not get loaded and threw an error. The other components consuming the reusable header also couldn't get loaded.
To resolve it... In the header file, I introduced an inner class and created the member variable and member function to the inner class. I created the object of the inner class as a member of the outer class. Now everything is working fine. All the components using the header are properly loading.
Can anyone please tell what could have gone wrong when the member variable and function was introduced for the outer class and how did it get resolved by using the inner class? I just know that by introducing the member variable to the outer class could have increased the dll size which might not be getting consumed properly. But, how did it get rectified by using inner class. Is the memory allocation playing a role here or, is it due to some other reason?
Below is the sample code from the reusable header that (1) didn't work and (2) did work:
(1)
class AFX_EXT_CLASS Class1
{
public:
Class1() {var = 8;};
void Func1(int local);
int var;
};
Note: Func1() gets called from multiple components other than the one it has been implemented into.
(2)
class AFX_EXT_CLASS Class1
{
public:
Class1();
class InnerClass
{
public:
InnerClass(): var(8) {}
void Func1(int local, Class1::InnerClass* objInnerClass)
{
objInnerClass->var = local;
}
int var;
};
public:
Class1::InnerClass objMainInnerClass;
//This object is used to call Func1() from the components using the reusable header.
};