Re: Alternatives to #define?
From: John Harrison (john_andronicus_at_hotmail.com)
Date: 07/02/04
- Next message: Jakub Wosko: "Re: C++ compiler"
- Previous message: John Harrison: "Re: Java to C++"
- In reply to: Carl Ribbegaardh: "Alternatives to #define?"
- Next in thread: Carl Ribbegaardh: "Re: Alternatives to #define?"
- Reply: Carl Ribbegaardh: "Re: Alternatives to #define?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 2 Jul 2004 13:29:40 +0100
"Carl Ribbegaardh" <carl_ribbegaardh.nospam@hotmail.com> wrote in message
news:2kl21iF3orqnU1@uni-berlin.de...
> What other c++ constructs can I use instead of #define for executing a
> couple of functions?
> Example:
>
> #define DO_STUFF doThis(); doThat();
>
> I'd guess that I can either use a template function, an inlined function
or
> an inlined static method.
>
> //1
> namespace MyUtils
> {
> template<>
> void doStuff()
> {
> doThis();
> doThat();
> }
> }
>
> //2
> namespace MyUtils
> {
> inline void doStuff()
> {
> doThis();
> doThat();
> }
> }
>
> //3
> class MyUtils
> {
> public:
> static inline void doStuff() const
> {
> doThis();
> doThat();
> }
> }
>
> I *believe* that the template version always is inlined, and that the
other
> 2 versions is probably inlined.
No that is not true. I guess you are thinking of the exception that
templates have from the normal one definition rules for functions and
classes. But that's an entirely seperate issue.
> Are theese approaches correct?
They are all correct.
> Which should be preferred?
The second
> Are there any other better way?
What's wrong with the second method? Why is it even an issue?
john
- Next message: Jakub Wosko: "Re: C++ compiler"
- Previous message: John Harrison: "Re: Java to C++"
- In reply to: Carl Ribbegaardh: "Alternatives to #define?"
- Next in thread: Carl Ribbegaardh: "Re: Alternatives to #define?"
- Reply: Carl Ribbegaardh: "Re: Alternatives to #define?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|