What does it mean to have a block of c++ code with

2020-08-09 09:55发布

I have recently seen blocks of C++ code where there is a "\" after each semicolon. It seems very odd to me. Perhaps it is nothing more than a mistake or the remnants of some long forgotten comments (although those have a forward slash "/" ). What impact would this "\" have on the code?

Her is a code sample.

#define PE_DECLARE_CLASS(class_) \
typedef class_ MyClass; \
static void setSuperClasses(); \

标签: c++ syntax
1条回答
叛逆
2楼-- · 2020-08-09 10:42

A backslash as last character in a line causes this line to be joined with the next for preprocessing. For regular C++ parsing newlines are simply whitespace, so this does not matter. But preprocessor directives, in particular macro definitions end at the end of line.

Using a backslash for line continuation allows formatting long macro bodies across multiple source text lines.

查看更多
登录 后发表回答