Atomic_Sheep
31st August 2013, 12:06
I'm trying to write a function with objects:
void System::SetBetaParameter()
{
if(conditions)
{
cBetaOne.m_bState = ENGAGED;
}
else if(alternate conditions)
{
cBetaOne.m_bState = DISENGAGED;
}
}
My case is simple with just two conditions and two objects, so theoretically I can just write two if loops testing for type of object being tested, but this is very cumbersome and I'm more interested in doing it by passing by reference or as a pointer.
Question that I have is, should I do the following:
System.h
#include "beta.h"
class System
{
Beta cBetaOne, cBetaTwo;
Beta *cBetaOne, *cBetaTwo;
}
Simply create the objects and then use their pointers after setting those pointers to correspond to those objects in the constructor or should I dynamically allocate those objects using new in the constructor and go from there?
void System::SetBetaParameter()
{
if(conditions)
{
cBetaOne.m_bState = ENGAGED;
}
else if(alternate conditions)
{
cBetaOne.m_bState = DISENGAGED;
}
}
My case is simple with just two conditions and two objects, so theoretically I can just write two if loops testing for type of object being tested, but this is very cumbersome and I'm more interested in doing it by passing by reference or as a pointer.
Question that I have is, should I do the following:
System.h
#include "beta.h"
class System
{
Beta cBetaOne, cBetaTwo;
Beta *cBetaOne, *cBetaTwo;
}
Simply create the objects and then use their pointers after setting those pointers to correspond to those objects in the constructor or should I dynamically allocate those objects using new in the constructor and go from there?