Solved

Getting rid of multiple function headers?

Posted on 2004-10-06
2
179 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

911 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

20 Experts available now in Live!

Get 1:1 Help Now