在 Visual Studio 2017(确切地说是 15.5.6)中使用 Visual C++ 时,我注意到 GCC 中的 __PRETTY_FUNCTION__
似乎可以工作! - 至少在某种程度上……
但是使用 __PRETTY_FUNCTION__
编译代码会导致错误:
error C2065: '__PRETTY_FUNCTION__': undeclared identifier
那么,有什么方法可以让它在 Visual C++ 中工作吗?有些可能包括?或者一些特殊的编译设置? (我想我使用的是默认值。)为什么它在所示示例中有效,但在实际使用中却无效?!
请注意,我不是在寻找 __PRETTY_FUNCTION__
的 Visual C++ 替代品。我已经认识他们了。我只是对这里的行为感到惊讶和好奇。
最佳答案
So, is there any way to make it work in Visual C++? Some include perhaps? Or some special compilation settings? (I think I'm using default ones.) Why would it work in shown examples, but not in actual use?!
没有。
Visual Studio 使用 Edison Design Group InteliSense 的 C++ 前端,如 Visual C++ 团队博客的 Rebuilding Intellisense 中所述和 here ,而不是 Microsoft C++ 编译器。这意味着 Intellisense 可用的某些功能在编译时不可用。
EDG 的 C++ Front End documentation提到它支持一些 GCC 预定义,例如第 71 页的 __PRETTY_FUNCTION__
- “1.13 Predefined Macros”以及 Microsoft 的 __FUNCSIG__
。
您甚至可以通过输入 __EDG_VERSION__
并将鼠标悬停在上面来查看 EDG 的版本。
关于c++ - Visual C++ 中的 __PRETTY_FUNCTION__,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48857887/