Solved

Getting rid of multiple function headers?

Posted on 2004-10-06
2
202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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.

749 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