Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
使用 Sun Studio 编译 C++ 代码时,我收到一些警告消息,这与不合时宜有关。有人可以解释一下 C++ 中的时代错误是什么吗?
还有如何在 Sun Studio 中关闭这些警告消息。
谢谢尼拉吉·拉蒂
时代错误是从 C 或 BCPL 等旧语言中借用的“功能”,不属于现代代码。
一个示例是const指向字符串文字的非指针:
const
char* p = "Hello World!";
摆脱警告的最好方法是修复代码。在上面的示例中,您将使用const-correctness:
const char* p = "Hello World!";