On Dec 10, 1:21 pm, Dean Sturtevant <
dsturtev...@google.com> wrote:
> I'm a little confused about your use case -- it might help to point to
> actual code.
> But it sounds to me like what you wanted to do was to make the
> function protected, not virtual.
> - Dean
>
> On Fri, Dec 10, 2010 at 11:47 AM, TTGator <
asorg...@gmail.com> wrote:
>
> > On Dec 10, 11:31 am, Dean Sturtevant <
dsturtev...@google.com> wrote:
> >> Note that if the base class calls a virtual function in its
> >> constructor, it's the base class's implementation that is used.
>
> >> Would it help in your case to write a factory?
>
> >> - Dean
>
> > I think that is fine here, because my intent was to make it virtual
> > only so I can call it from the mock class, and pass it whatever
> > parameters I want to test the function. Right?
>
>
So it looked a little like this... (and yes, I know the error handling
is aweful... again... legacy code here)
MyClass::MyClass (int foo, int bar)
: m_SuspendSemaphore(0),
m_bSuspended(false),
m_phMainState(NULL),
m_phSubstate(NULL),
m_bShuttingDown(false),
m_phVersionNum(NULL),
m_phPreviousMode(NULL),
m_phSupportSettings(NULL),
m_pMessageFactory(MessageFactory::GetSoleInstance()),
m_pActiveMessage(NULL),
m_EventCountSemaphore(0),
m_pIllegalEvent(NULL),
m_TService(this),
{
...Code to register a bunch of services and handlers here that
would not exist during unit testing...
// Read values from the global configuration file
bool b_flag1;
bool b_flag2;
...
try
{
b_flag1 = ConfigSys::GetSoleInstance()-
>GetBoolValue(ConfigConstants::CFlag1);
b_flag2 = ConfigSys::GetSoleInstance()-
>GetBoolValue(ConfigConstants::CFlag2);
...
}
catch (ConversionError& ex)
{
ERROROUT(__PRETTY_FUNCTION__ << ": Caught Exception: " <<
ex.GetDesc() << endl);
}
catch (ItemDoesNotExist& ex)
{
ERROROUT(__PRETTY_FUNCTION__ << ": Caught Exception: " <<
ex.GetDesc() << endl);
// Initialize my stuff (this is where my actual code change was
made, in this huge ugly block, so I took this chunk of code and made
it a function
MyClass::InitMyPart(b_flag1, b_flag2);
...Lots more code here below, which some of it acts on the flags
read from the global config file...
... More code that instantiates hardware dependent stuff, hence
more of my need to mock...
} //MyClass
void MyClass::InitMyPart( bool b_flag1, bool b_flag2 )
{
... Code to create a table with the values of the flags...
}