I'm not sure if I understand the problem, but have you tried using a polymorphism approach?
That is, let's say you have an abstract base class MeasurementDevice:
1 2 3 4 5 6 7 8 9 10 11
|
class MeasurementDevice
{
private:
double value;
// ...
public:
virtual void PrintStuff();
virtual void ControlStuff();
virtual double Retrieve();
// ...
};
|
You can then have concrete classes that inherit from this class, hence conforming to the behaviour of a MeasurementDevice. Let's say we want a Voltmeter.
1 2 3 4 5 6 7 8 9 10
|
class Voltmeter: public MeasurementDevice
{
private:
bool canMeasureImpedence; // Other attributes specific to Voltmeters
public:
void PrintStuff();
void ControlStuff();
double Retrieve();
// ...
};
|
Now, you can use polymorphism and do the following:
MeasurementDevice * myVoltmeter = new Voltmeter();
You could also have a collection which stores MeasurementDevice objects, with each element of the collection being a Voltmeter or another type of MeasurementDevice. Check out
http://www.cplusplus.com/doc/tutorial/polymorphism/ for more info on this idea.
So, to answer your original question, I think you could simply do:
A b = B()
I should say that I'm not as experienced as some of the other guys around here, so we should hear what they have to say about it too :).