Solved

Getting rid of multiple function headers?

Posted on 2004-10-06
2
169 Views
Last Modified: 2010-04-01
There has to be a better way to do what I want to do.

I am currently doing this:

-In my Flow.h file I have this -
#if HARDWARETYPE1
      virtual int  SocketReceive(HardwareType1Startup* pHardware1StartupObj);
#elif HARDWARETYPE2
      virtual int  SocketReceive(HardwareType2Startup* pHardware2StartupObj);
#elif HARDWARETYPE3
      virtual int  SocketReceive(HardwareType3Startup* pHardware3StartupObj);
#endif

-So now in my Flow.cpp file I have this-
#if HARDWARETYPE1
int CFlow::SocketReceive(HardwareType1Startup* pHardware1StartupObj)
#elif HARDWARETYPE2
int CFlow::SocketReceive(HardwareType2Startup* pHardware2StartupObj)
#elif HARDWARETYPE3
int CFlow::SocketReceive(HardwareType3Startup* pHardware3StartupObj)
#endif
{
       ....
       ....
}

Is there a better way to combine the function headers so that I don't have 3 different ones depending on what build I am using?
0
Comment
Question by:mcravenufo
2 Comments
 
LVL 3

Expert Comment

by:Indrawati
ID: 12244426
Well, if you have access to the source code for HardwareTypeXStartup, you can create a common base class for all of them and manipulate each Startup object with a pointer to this base class. Or you can also use template to achieve similar effect.
0
 
LVL 17

Accepted Solution

by:
rstaveley earned 125 total points
ID: 12245931
Define three classes derived from CFlow:

CFlowHardwareType1
CFlowHardwareType2
CFlowHardwareType3

Implement SocketReceive in the derived classes.

Only link the derived class that you need in your build.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now