C++/CLI:如何在 C++/CLI 中声明抽象(在 C# 中)类和方法?

发布于 2024-08-14 05:03:13 字数 137 浏览 11 评论 0原文

以下 C# 代码在 C++/CLI 中的等价物是什么?

public abstract class SomeClass
{
    public abstract String SomeMethod();
}

What is the equivalent of the following C# code in C++/CLI?

public abstract class SomeClass
{
    public abstract String SomeMethod();
}

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

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

发布评论

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

评论(2

笑咖 2024-08-21 05:03:13

只需稍微混合一下关键字即可得到正确的语法。 abstract 在 C# 中位于前面,但在 C++/CLI 中位于末尾。与 override 关键字相同,如今 C++11 兼容编译器也能识别该关键字,这些编译器希望将其放在函数声明的末尾处。就像传统 C++ 中的 = 0 一样来标记函数抽象:

public ref class SomeClass abstract {
public:
  virtual String^ SomeMethod() abstract;
};

Just mix up the keywords a bit to arrive at the correct syntax. abstract goes in the front in C# but at the end in C++/CLI. Same as the override keyword, also recognized today by C++11 compliant compilers which expect it at the end of the function declaration. Like = 0 does in traditional C++ to mark a function abstract:

public ref class SomeClass abstract {
public:
  virtual String^ SomeMethod() abstract;
};
国粹 2024-08-21 05:03:13

您使用抽象

public ref class SomeClass abstract
{
    public:
        virtual System::String^ SomeMethod() = 0;
}

You use abstract:

public ref class SomeClass abstract
{
    public:
        virtual System::String^ SomeMethod() = 0;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文