关于我在 C 语言中从未见过的特殊运算符的一些问题; 代码

发布于 2024-07-22 04:56:01 字数 1274 浏览 2 评论 0原文

我已经下载了Phoenix SDK June 2008(编译器工具),当我阅读Hello示例的代码时,我真的感到失落。

public
ref class Hello
{
//--------------------------------------------------------------------------
//
// Description:
//
//    Class Variables.
//
// Remarks:
//
//    A normal compiler would have more flexible means for holding
//    on to all this information, but in our case it's simplest (if
//    somewhat inelegant) if we just keep references to all the
//    structures we'll need to access as classstatic variables.
//
//--------------------------------------------------------------------------

static Phx::ModuleUnit                 ^ module;
static Phx::Targets::Runtimes::Runtime ^ runtime;
static Phx::Targets::Architectures::Architecture       ^ architecture;
static Phx::Lifetime                   ^ lifetime;
static Phx::Types::Table               ^ typeTable;
static Phx::Symbols::Table                ^ symbolTable;
static Phx::Phases::PhaseConfiguration        ^ phaseConfiguration;

2 个问题: ref 关键字是什么? 那个符号^是什么? 它在做什么

protected:

  virtual void
  Execute
  (
     Phx::Unit ^ unit
  ) override;

};

override 也是 C++ 关键字吗? 它在我的 Visual Studio 中是这样着色的。 我很想玩一下这个框架,但是这个高级的C++现在确实是一个障碍。 谢谢。

I have downloaded the Phoenix SDK June 2008 (Tools for compilers) and when I'm reading the code of the Hello sample, I really feel lost.

public
ref class Hello
{
//--------------------------------------------------------------------------
//
// Description:
//
//    Class Variables.
//
// Remarks:
//
//    A normal compiler would have more flexible means for holding
//    on to all this information, but in our case it's simplest (if
//    somewhat inelegant) if we just keep references to all the
//    structures we'll need to access as classstatic variables.
//
//--------------------------------------------------------------------------

static Phx::ModuleUnit                 ^ module;
static Phx::Targets::Runtimes::Runtime ^ runtime;
static Phx::Targets::Architectures::Architecture       ^ architecture;
static Phx::Lifetime                   ^ lifetime;
static Phx::Types::Table               ^ typeTable;
static Phx::Symbols::Table                ^ symbolTable;
static Phx::Phases::PhaseConfiguration        ^ phaseConfiguration;

2 Questions : What's that ref keyword?
What is that sign ^ ? What is it doing

protected:

  virtual void
  Execute
  (
     Phx::Unit ^ unit
  ) override;

};

override is a C++ keyword too? It's colored as such in my Visual Studio.
I really want to play with this framework, but this advanced C++ is really an obstacle right now. Thank you.

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

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

发布评论

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

评论(4

赏烟花じ飞满天 2024-07-29 04:56:01

它不是标准 C++,而是 C++/CLI

It's not standard C++, it's C++/CLI.

稚然 2024-07-29 04:56:01

它是与 .NET 一起使用的 Microsoft 扩展。 插入符号指示存储在托管堆上的对象的句柄。 有关详细说明,请参阅 Bran Bray 的博客。

It's a Microsoft extension for use with .NET. The caret indicates a handle to an object stored on the managed heap. See Bran Bray's blog for a nice description.

旧话新听 2024-07-29 04:56:01

它是 C++/CLI - 编写为在 .Net 框架下作为托管代码运行的代码,而不是常规 C++ 代码。

  • ref - 此类是引用类型,它在托管堆中分配并将被垃圾收集
  • ^ - 此变量是托管实例的句柄
  • override - 此方法覆盖基类实现

It is C++/CLI - code that is written to be run as managed code under the .Net framework, not regular C++ code.

  • ref - this class is a reference type, it is allocated in the managed heap and will be garbage collected
  • ^ - this variable is a handle to a managed instance
  • override - this method overrides the base class implementation
ㄟ。诗瑗 2024-07-29 04:56:01

这不是标准 C++ 的一部分。 它是 C++/CLI,这是一种 Microsoft 语言规范,旨在取代托管 C++

C++/CLI(通用语言
基础设施)是微软的
语言规范旨在
取代 C++ 的托管扩展。
彻底修改以简化
较旧的托管 C++ 语法(现在是
已弃用),它提供了更多
清晰度和代码可读性优于
托管 C++。 C++/CLI 已标准化
由 Ecma 命名为 ECMA-372。 目前是
仅在 Visual Studio 2005 中可用
和 2008 年(也包括在 Express 中)
版本)。

插入符号在 C++/CLI 中相当于指针,如 Rob Walker 对 这个问题

...插入符号是托管的等效项
C++/CLI 中的 *(指针)
术语称为“句柄”
“引用类型”(因为您仍然可以
有非托管指针)。 看到这个
概述
来自微软。

在此 博客文章

That is not part of standard C++. It's C++/CLI, which is a Microsoft language specification designed to replace Managed C++:

C++/CLI (Common Language
Infrastructure) is Microsoft's
language specification intended to
supersede Managed Extensions for C++.
Completely revised to simplify the
older Managed C++ syntax (which is now
deprecated), it provides much more
clarity and code readability than
Managed C++. C++/CLI is standardized
by Ecma as ECMA-372. It is currently
only available in Visual Studio 2005
and 2008 (also included in the Express
Editions).

The caret symbol is the C++/CLI equivalent of a pointer, as described in Rob Walker's answer to this question:

...the caret is the managed equivalent
of a * (pointer) which in C++/CLI
terminology is called a 'handle' to a
'reference type' (since you can still
have unmanaged pointers). See this
overview
from Microsoft.

The usage of "ref class X" instead of the familiar "class X" is discussed in this blog post.

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