Can I default a function argument to the value of

2019-04-28 17:15发布

In C++, can I have a defaulted argument to a function which defaults to __PRETTY_FUNCTION___, ___FILE___, and ___LINE__ as defined at the point of the caller and not the point the defaults are supplied in a header file without using macros?

3条回答
Anthone
2楼-- · 2019-04-28 17:36

No. Macros are expanded at the source line where they occur.

查看更多
3楼-- · 2019-04-28 17:40

You probably can... but definitely not with the restriction you mentioned (no macros).

查看更多
beautiful°
4楼-- · 2019-04-28 17:47

You can't, but you can acheive this behavior with an additional macro. For instance:

#DEFINE THROW(e) throwException(e, __FILE__, __LINE__);

On a side note, __PRETTY_FUNCTION__ is not standard.

查看更多
登录 后发表回答