确保 VS 2008 将我的项目视为 C++而不是 C++/CLI

发布于 2024-11-15 01:06:34 字数 827 浏览 2 评论 0原文

我正在使用本机 C++ 在 Visual Studio 2008 中工作。

一位同事编写了一个库,并将其中一个类命名为interface。这是一个构造函数:

template <typename DtedInterface>
interface<DtedInterface>::interface (
    std::string const& tleFile,
    std::string const& dtedDir,
    dted::DtedLevel const& dtedLevel,
    double sw_latitude,
    double sw_longitude,
    unsigned int rows,
    unsigned int columns )
    : m_impl ( new interface_impl<DtedInterface> ( theFile, dtedDir, dtedLevel, sw_latitude, sw_longitude, rows, columns ) )
  {}

令我担心的是 Visual Studio 2008 突出显示了 interface 一词作为关键字; interface 是 C++/CLI 中的关键字,但不是 C++ 中的关键字。这看起来不像是有效的 C++/CLI,但对于本机 C++ 来说没问题。

看起来编译得很好,但如何确保 Visual Studio 将其解释为 C++ 而不是 C++/CLI?在某种程度上,VS 似乎将其视为 C++/CLI。它只是一个关键字突出显示设置吗?

I'm working in Visual Studio 2008 with native C++.

A colleague wrote a library, and he named one of his classes interface. Here's a constructor:

template <typename DtedInterface>
interface<DtedInterface>::interface (
    std::string const& tleFile,
    std::string const& dtedDir,
    dted::DtedLevel const& dtedLevel,
    double sw_latitude,
    double sw_longitude,
    unsigned int rows,
    unsigned int columns )
    : m_impl ( new interface_impl<DtedInterface> ( theFile, dtedDir, dtedLevel, sw_latitude, sw_longitude, rows, columns ) )
  {}

What concerns me is that Visual Studio 2008 is highlighting the word interface as a keyword; interface is a keyword within C++/CLI but not C++. This doesn't look like it would be valid C++/CLI, but it's fine for native C++.

Things look like they compile fine, but how do I make sure that Visual Studio is interpreting this as C++ rather than C++/CLI? At some level, it appears that VS views this as C++/CLI. Is it just a keyword highlighting setting?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

贪恋 2024-11-22 01:06:34

Visual Studio IDE 和 Visual C++ 编译器是两个独立的实体。具体来说,它们是作为单独进程运行的两个单独的可执行文件(用于 IDE 的 devenv.exe 和用于编译器的 cl.exe)。 IDE 只是生成 cl.exe 进程来执行实际的编译。

IDE 在某处有一个关键字列表,它只是告诉文本编辑器要突出显示哪些单词。它并不是超级复杂;不一定是这样。编译器拥有最终决定权,而不是语法荧光笔(或智能感知)。

只要 /clr 开关如果不传递给 cl.exe 进程,编译器会将代码编译为本机 C++(这是默认设置)。 IDE 只需输入源代码的文件路径,编译器就会作为命令行参数切换到 cl.exe 进程。语法突出显示与编译器如何解释代码无关。

The Visual Studio IDE and the Visual C++ compiler are two separate entities. Specifically, they are two separate executables (devenv.exe for the IDE and cl.exe for the compiler) that run as separate processes. The IDE simply spawns the cl.exe process to perform the actual compilation.

The IDE has a list of keywords somewhere that simply tells the text editor which words to highlight. It isn't super sophisticated; it doesn't have to be. The compiler has the final say, not the syntax highlighter (or Intellisense for that matter).

As long as the /clr switch is not being passed to the cl.exe process, the compiler will compile the code as native C++ (which is the default setting). The IDE simply feeds in the file paths of your source code and the compiler switches as command-line arguments to the cl.exe process. The syntax highlighting has no bearing on how the compiler interprets the code.

唱一曲作罢 2024-11-22 01:06:34

如果您使用的是 C++/CLI,代码将拒绝编译,因此只要您按下“build”并且它可以工作,那么您就知道您处于本机环境中。还有用于 CLR 构建的预定义宏。

The code will refuse to compile if you're in C++/CLI, so as long as you push "build" and it works, then you know you're in native. There are also pre-defined macros for CLR builds.

情魔剑神 2024-11-22 01:06:34

如果您确实需要验证它没有编译托管 C++,请查看项目属性并检查“配置属性”->“常规”下的“公共语言运行时支持”设置。对于“配置属性”->“C/C++”->“常规”下的每个文件的属性,检查“使用公共语言运行时支持进行编译”设置。如果所有这些都设置为“无公共语言运行时支持”,则该项目不是托管 C++。

If you're really need to verify it's not compiling managed C++, look at the project properties and check the "Common Language Runtime support" setting under the Configuration Properties->General. As well for each file's properties under Configuration Properties->C/C++->General check the "Compile with Common Language Runtime support" setting. If all of those are set to "No Common Language Runtime support", the project is not managed C++.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文