Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

macro-problems

14 views
Skip to first unread message

Bonita Montero

unread,
Feb 25, 2021, 1:24:56 AM2/25/21
to
I've got a header with a macro to define new exception-subclasses:

#pragma once
#include <exception>
#include <string>

#define exc_subclass(base, deriv, default_what) \
struct deriv : public base \
{ \
deriv( char const *what = default_what ) noexcept : \
m_what( what ) \
{ \
} \
deriv( exception_ptr nextException, char const *what = default_what )
noexcept : \
m_nextException( nextException ), \
m_what( what ) \
{ \
} \
deriv( deriv const &other ) noexcept : \
base( other ), \
m_what( other.what() ) \
{ \
} \
virtual char const *what() const noexcept override \
{ \
return m_what.c_str(); \
} \
std::exception_ptr next_exception() const noexcept \
{ \
return m_nextException; \
} \
private: \
std::string m_what; \
std::exception_ptr m_nextException; \
};

But this doesn't accept ...
exc_subclass(std::exception, deriv, "my default what")
... because of the :: in it.
Is there any escape for :: ?

Ben Bacarisse

unread,
Feb 25, 2021, 6:11:45 AM2/25/21
to
The macro does not care about the ::. If it does not work, it's for
some other reason.

--
Ben.

Paavo Helde

unread,
Feb 25, 2021, 6:43:42 AM2/25/21
to
25.02.2021 08:24 Bonita Montero kirjutas:
> I've got a header with a macro to define new exception-subclasses:
>
> #pragma once
> #include <exception>
> #include <string>
>
> #define exc_subclass(base, deriv, default_what) \
> struct deriv : public base \
> { \
>     deriv( char const *what = default_what ) noexcept : \
>         m_what( what ) \
>     { \
>     } \
>     deriv( exception_ptr nextException, char const *what = default_what

You are missing std:: before exception_ptr in the prev line.

Colons in preprocessor macros are fine. Commas, on the other hand, might
be a bit tricky sometimes.



Bonita Montero

unread,
Feb 25, 2021, 8:54:54 AM2/25/21
to
> You are missing std:: before exception_ptr in the prev line.

Ok, that's what someone else found on Stack Overflow also.
But thanks.

0 new messages