Solved

Getting rid of multiple function headers?

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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. …
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 concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

626 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