tags:

views:

86

answers:

2

Is this a macro defintion for a class or what exactly is it?

#define EXCEPTIONCLASS_IMPLEMENTATION(name, base, string) : public base     \
    {                                                               \
public:                                                                 \
    name() : base(string) {}                                            \
    name(const x::wrap_exc& next) : base(string,next) {};               \
    name(const x::wrap_exc& prev, const x::wrap_exc& next) :            \
        base(prev, next) {};                                            \
}
+3  A: 

it is macro for exception, that creates exception with standard constructors.

Andrey
so is the name () a constructor of some class or is it a parameter???
Tony
@Tony it is constructor of this class. when you write in code `EXCEPTIONCLASS_IMPLEMENTATION(DivByZeroException, MathException, "")` it will expand to ... DivByZeroException() : MathException("") {}
Andrey
+8  A: 

It is a macro definition for an exception class.

It looks somebody wants you to write code like this:

class my_exception EXCEPTIONCLASS_IMPLEMENTATION(my_exception, std::exception, "What a mess!")

The pre-processor will spit out:

class my_exception : public std::exception { public: my_exception() : std::exception("What a mess!") {} my_exception(const x::wrap_exc& next) : std::exception("What a mess!",next) {}; my_exception(const x::wrap_exc& prev, const x::wrap_exc& next) : std::exception(prev, next) {}; }

What exactly is it?

It is an abomination!

Johnsyweb
Aside from the fact that it requires you to type out the class head before the macro, I don't think that's an abomination. Anything that saves typing is useful, IMO.
James McNellis
I'm amazed that the person creating this macro didn't complete the class definition by including `class name`. That aside, anything that is unclear to an experienced programmer is not useful as it makes maintenance a nightmare.
Johnsyweb