Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Getting rid of multiple function headers?

Posted on 2004-10-06
2
Medium Priority
?
218 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 500 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
  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 …
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.
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.

660 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