Im trying to create a DLL consisting of C++ classes including inheritance. The DLL is supposed to be accessed by some console application.
Parent class:
paramCalculator.h
#ifdef MY_EXPORTS
#define PARAMCALCULATOR __declspec(dllexport)
#else
#define PARAMCALCULATOR __declspec(dllimport)
#endif
class PARAMCALCULATOR paramCalculator
{
public:
paramCalculator();
~paramCalculator();
float m_current;
};
paramCalculator.cpp
#include "stdafx.h"
paramCalculator::paramCalculator()
{
}
paramCalculator::~paramCalculator()
{
}
Child class:
currentCalculator.h
#ifdef MY_EXPORTS
#define PARAMCALCULATOR __declspec(dllexport)
#else
#define PARAMCALCULATOR __declspec(dllimport)
#endif
class PARAMCALCULATOR currentCalculator :
public paramCalculator
{
public:
currentCalculator();
~currentCalculator();
float m_tubePower = 1500;
float m_tubeCurrent;
void calcCurrent(float vo);
};
currentCalculator.cpp
#include "stdafx.h"
currentCalculator::currentCalculator()
{
}
currentCalculator::~currentCalculator()
{
}
void currentCalculator::calcCurrent(float vo)
{
m_tubeCurrent = m_tubePower / vo;
std::cout << m_tubeCurrent << std::endl;
m_current = m_tubeCurrent;
}
The console application accessing the DLL looks as follows:
#include "paramCalculator.h"
#include "currentCalculator.h"
class tubeCurrent
{
public:
tubeCurrent() {};
~tubeCurrent() {};
void setParam(float v)
{
ab.calcCurrent(v);
m_current = ab.m_tubeCurrent;
}
currentCalculator ab;
float m_current;
};
int main()
{
tubeCurrent ac;
float voltage = 200;
ac.setParam(voltage);
}
When running the console application it shows "7.5" on the output window, which is the expected calculated value for the current. This tells me that accessing the DLL works. However, the variables m_tubeCurrent and m_current have not been changed to value 7.5. Can anyone tell me how to fix this and get both variables to update its values?
During some tests i've found out that as soon as I remove the inheritance relation between both classes, the member variable "m_tubeCurrent" are updated successfully. However, im struggling to find a way to access the member variables when inheritance between both classes is involved.
I've gone through this question but couldn't solve my issue.
Thanks in advance!
Edit:
In order to make myself more clear, here's two images of the debug window within the console application.
Inheritance is included and the calculated values are not assigned to the corresponding variables:
No inheritance resulting in the calculated values being assigned to the corresponding variables:
In the latter one, I have only changed the currentCalculator class definition within the currentCalculator.h file from
class PARAMCALCULATOR currentCalculator :
public paramCalculator:
to
class PARAMCALCULATOR currentCalculator
Both variants calculate the values in the right manner when the DLL is executed, however only the latter one allows me to still access the variables after the DLL has been executed.

