By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,332 Members | 1,404 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,332 IT Pros & Developers. It's quick & easy.

using preprocessors - help!!

P: n/a
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)

Dec 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
In article <11**********************@g14g2000cwa.googlegroups .com>,
Jamiil <ja******@netscape.net> wrote:
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++ .
--
"No one has the right to destroy another person's belief by
demanding empirical evidence." -- Ann Landers
Dec 18 '05 #2

P: n/a
Jamiil wrote:
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

Dec 18 '05 #3

P: n/a
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.

Robert Gamble wrote:
Jamiil wrote:
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


Dec 19 '05 #4

P: n/a
"Jamiil" <ja******@netscape.net> writes:
Robert Gamble wrote:
Jamiil wrote:
> 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++.

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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Dec 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.