using preprocessors - help!!

J

Jamiil

I have a class which only purpose is to provide services to a variety
of classes in other files. The 'manipulator' class is aware of the
other classes only because the header files have been include in its
header file. However, there are times when some of the other classes
are not and will not be dealt with, thus the need to include the header
files does not arrive. To handle this, I have used compiler
preprocessors to prevent the unneeded header files and method
declarations / implementations to be compiled, here is an example:

--- popeye.hpp ---
#ifndef POPEYE_HPP
#define POPEYE_HPP
class popeye{ /*the whole enchilada goes here */};

--- mikey.hpp ---
#ifndef MIKEYMOUSE_HPP
#define MIKEYMOUSE_HPP
class mikey{ /*more cheese senior?*/ };

--- donal.hpp ---
#ifndef DONALDUCK_HPP
#define DONALDUCK_HPP
class duck{ /* para bailar la banba */};

--- manipulator.hpp ---
#ifndef MANIPULATOR_HPP
#define MANIPULATOR_HPP
#ifdef POPEYE_HPP
#include "popeye.hpp"
#endif
#ifdef MIKEYMOUSE_HPP
#include "mikey.hpp"
#endif

#ifdef DONALDUCK_HPP
#include "donal.hpp"
#endif

class manipulator{
private:
..........
protected:
..........
public:
..........
#ifdef POPEYE_HPP
void handle_popeye(const popeye&);
#endif

#ifdef MIKEMOUSE_HPP
void handle_mikey(const mikey&);
#endif

#ifdef DONALDUCK_HPP
void handle_duck(const duck&);
#endif
.........
};
#ifdef POPEYE_HPP
void manipulator::handle_popeye(const popeye& p){/*...*/}
#endif
#ifdef MIKEMOUSE_HPP
void manipulator::handle_mikey(const mikey& p){/*...*/}
#endif
#ifdef DONALDUCK_HPP
void manipulator::handle_duck(const duck& p){/*...*/}
#endif
--- main.cpp --
#include "popeye.hpp"
#include "manipulator"

int main(){
popeye p;
manipulator m;
m.handle_popeye(p); //<<== segmentation fault
return 0;
}

My question is: why is it that if I remove the conditional
preprocessors I don't get a segmentation fault?


T. I. A. F.
(Thank In Advance Folks)
 
W

Walter Roberson

I have a class which only purpose is to provide services to a variety
of classes in other files.

The C language does not have any notion of "class".
class popeye{ /*the whole enchilada goes here */};

That appears to be a C++ question. Please ask in comp.lang.c++ .
 
R

Robert Gamble

Jamiil said:
I have a class which only purpose is to provide services to a variety
of classes in other files. The 'manipulator' class is aware of the

This is a group about C which does not have these "classes" you speak
of. Try comp.lang.c++.

Robert Gamble
 
J

Jamiil

Thanks folks for your prompt response.
Yes, I know that, but the question is about compiler preprocessors not
about C++; it just happens to be in an hpp file. With a little
imagination one could very quickly convert the example to a C program.


Thanks anyway.
 
K

Keith Thompson

Jamiil said:
Thanks folks for your prompt response.
Yes, I know that, but the question is about compiler preprocessors not
about C++; it just happens to be in an hpp file. With a little
imagination one could very quickly convert the example to a C program.

Thanks anyway.

Please don't top-post. Your response goes below any quoted text.

You posted C++ code. The folks in comp.lang.c++ can help you with it.

If you want help with a C code, you'll need to post some; we won't
convert it for you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top