473,546 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Header and Classes Question

I have two programs, ProgramA and ProgramB, they both use a common
header, well I am wanting to use a common header, if possible. This is
similiar to what I have, in ProgramA.h I have the code:

#if !defined(Progra mA)
#define ProgramA

The problem is, that it always goes into the #else section, am I
missing something?

//Rules.h

#if !defined(RULESI ncluded)
#define RULESIncluded

#ifdef ProgramA
#include "Branch.h"
#include <vector>

class Rules
{
public:
Rules(char *iniFile);
~Rules();
static inline bool IsValid(char* text);
static Data* GetData(const char* name);
private:
static std::vector<Dat a*> names_vec;
};
#else
class Rules
{
public:
Rules();
~Rules();
static inline bool IsValid(char* text);
};
#endif

bool Rules::IsValid( char* text)
{
//Code Here
return true;
}
#endif

Nov 22 '05 #1
1 1155
mr********@yaho o.com wrote:
I have two programs, ProgramA and ProgramB, they both use a common
header, well I am wanting to use a common header, if possible. This is
similiar to what I have, in ProgramA.h I have the code:

#if !defined(Progra mA)
#define ProgramA

The problem is, that it always goes into the #else section, am I
missing something?
This seems like an awfully complicated construction. What are you
really trying to accomplish?

When you say it always goes into the #else section I'm guessing you're
referring to the code below. Keep in mind that unless you #include
"Rules.h" _after_ you #define ProgramA, then ProgramA will not be
#defined when Rules.h is input. It would be helpful if you showed us a
complete set of files that exhibits this problem.

It seems like you're trying too hard to use preprocessor directives.
Since the preprocessor is relatively dumb and the compiler is relatively
smart, it's generally a good idea to rely on the preprocessor as little
as possible.

The #ifndef NAME #define NAME ... #endif pattern is usually employed as
an include guard, i.e., a way to make sure that a header doesn't get
included multiple times during the compilation of a single translation
unit (think .cpp file). It's rather less common to use it to make
logical decisions about what the code should look like and I'd advise
against doing so unless you have good reasons. If the class Rules is
different for ProgramA and ProgramB either make two separate headers or
abstract out only the similar parts, but I'd still recommend the former.

Mark

//Rules.h

#if !defined(RULESI ncluded)
#define RULESIncluded

#ifdef ProgramA
#include "Branch.h"
#include <vector>

class Rules
{
public:
Rules(char *iniFile);
~Rules();
static inline bool IsValid(char* text);
static Data* GetData(const char* name);
private:
static std::vector<Dat a*> names_vec;
};
#else
class Rules
{
public:
Rules();
~Rules();
static inline bool IsValid(char* text);
};
#endif

bool Rules::IsValid( char* text)
{
//Code Here
return true;
}
#endif

Nov 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5115
by: dharmesh Gupta | last post by:
Hi All, i am new to header files , and have a basic question , i have made my program in three files namely, idr_bpl.cpp( contains class definitions and function definitions) bpl.cpp( contains main() function) bpl.h (contains variable definition of a variable that is shared in the above two files )
11
2735
by: Steven T. Hatton | last post by:
In the past there have been lengthy discussiions regarding the role of header files in C++. People have been very adamat about header files serving as in interface to the implementation. I do understand the objective. This example may represent an interface in need of a bit of refactoring, but it goes to demonstrate the basic idea as I...
15
7859
by: Kannan Goundan | last post by:
Maintaining a C++ header file can be painful. I want a way to automatically generate header files from the implementation file. Does anybody know of a program that does this? If not, I'd like to try writing one. The input file would consist of function definitions and class definitions (with all methods defined inline). The program...
4
2833
by: Adam Clauss | last post by:
OK, lets say I have a C# Windows application. In it is a a series of namespaces, all rooted for a certain namespace A. For ex, the "using" directives would read something like: using A; using A.somenamespace; using A.anothernamespace; Now, other users will be using these namespaces. I would like for them to be able to take advantage...
0
3916
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen. It is almost like it is trying to implement it's own COM interfaces... below is the header, and a link to the dll+code: Zip file with header,...
3
1233
by: Søren M. Olesen | last post by:
Hi What would be the easiest way, to write an 'AppleDouble file header' to a file, from vb.net?? AppleDouble file header: -------------------------------------------------------------------------------- Field Length -------------------------------------------------------------------------------- Magic...
1
1418
by: Greg | last post by:
Hi, In a C++/CLR Windows Forms app I notice that there is only a header and no ..cpp for the form. Also event handler bodies are added by the IDE right to the header. What is the philosophy on this? 1. Are C++ and/or C++/CLR classes now intended to be typically implemented in the header?
6
42993
by: Peter van der veen | last post by:
Hi I have the following problem. I'm calling a webservice from within a VB.net 2005 Windows program. For this i got a WSDL file and loaded that in VB. Until now i just call the webservice and everything works OK. Now i need to add an extra attribute/header element to the SOAP header before i contact the webservice.
6
3969
by: Joseph Geretz | last post by:
I have the following class which I am serializing and passing back and forth between my Web Service application and the client. public class Token : SoapHeader { public string SID; public string UID; public string PWD; }
1
2774
by: Swapnil Kale | last post by:
Hi, I'm working on a Migration project (Forte to JAVA). The forte client had a C++ dll which used to call one more FORTE dll for a complex database calculations. Now all the forte code has been migrated to JAVA except this piece of code where C++ dll calls Forte DLL.
0
7507
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7461
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7794
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6030
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5361
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3472
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1922
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.