为什么在 c++ 中公开引用 类定义

发布于 2024-07-29 16:30:54 字数 327 浏览 13 评论 0原文

首先,我想澄清一下,我对 C++ 都是新手,所以这可能是一个简单且有些明显的问题。 在我正在阅读的 C++ 书籍《C++ Primer》中,类是通过以下方式定义的:

class classname{
public:

private:

};

但是,在 VS2008 中,编译器不喜欢这样。 但是通过在类之前添加公共引用,如下所示:

public ref class classname{

它在编译器中经过了。 谁能解释一下仅使用类定义和使用公共引用类定义之间有什么区别? 我真的很感激。

First of all I want to make clear that 'm all new to C++, so this might be a simple and somewhat obvious question. In the C++ book I'm reading called C++ Primer, a class is defined by writing:

class classname{
public:

private:

};

However, in VS2008 the compiler didnt like this. But by adding public ref before class, as in:

public ref class classname{

it went through in the compiler. Can anyone please explain what the difference is between defining only with class and with public ref class? I would really appreciate it.

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

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

发布评论

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

评论(4

土豪我们做朋友吧 2024-08-05 16:30:54

ref 语法是仅在托管 C++ 中使用的 Microsoft 扩展。 从声音来看,您在创建项目时错误地打开了 /clr 编译器开关。 如果您只想创建真正的 C++ 程序,那么您将需要恢复它。

The ref syntax is a Microsoft extension used only in Managed C++. By the sounds of things you have flicked the /clr compiler switch on by mistake when creating your project. If all you want to do is to create real C++ programs, then you will want to revert that.

月下伊人醉 2024-08-05 16:30:54

您正在阅读一本名为《C++ Primer》的书,该书教授 C++ 编程语言,而您正在尝试创建一个程序,告诉 VC++ 代码位于 C++/CLI,一种不同的编程语言......

You're reading a book call C++ Primer which teaches the C++ programming language, whereas you're attempting to create a program telling VC++ the code is in C++/CLI, a different programming language....

北笙凉宸 2024-08-05 16:30:54

您(编辑:和其他用户)将此问题标记为:

  • 两种编程语言C++C++/CLI
  • Microsoft 的一款商业集成开发环境 (IDE)Visual C++,它允许您使用三种不同的语言进行编程 (C、C++ 和 C++/CLI)。 在帖子中您提到Microsoft Visual Studio 2008,这是一个Visual C++ 的超集。
  • 一组语言扩展托管 C++,它在历史上指的是相当多不同的事物,坦率地说,我不确定它现在意味着什么:)

但是,您的第一个目标应该是学习如何配置 Visual C++使用您选择的语言 C++ 进行编程。

像往常一样,找到此问题答案的一个好方法是在“提问”页面中输入该问题,然后查看建议的相关问题。 我认为这是最好的:编译“标准” Visual Studio 中的 C++(非 .net)

You (edit: and other users) tagged this question with:

  • Two programming languages: C++ and C++/CLI,
  • One commercial Integrated Development Environment (IDE) by Microsoft: Visual C++, which lets you program in three different languages (C, C++ and C++/CLI). In the post you mention Microsoft Visual Studio 2008, which is a superset of Visual C++.
  • One set of language extensions: Managed C++, which has historically refered to quite a few different things and, frankly, I'm not sure what it means now :)

However, your first goal should be to learn how to configure Visual C++ to program in the language of your choice, C++.

As usual, a good way to find an answer to this question is to type it in the "Ask Question" page and see which related questions are suggested. This is the best one, I think: compiling "standard" C++ in visual studio (non .net).

岁月静好 2024-08-05 16:30:54

您正在学习标准 C/C++ 语言吗? 如果答案是肯定的,那么该语法与 Microsoft C++/CLI 语言有关...

请查看: C++/CLI

尝试使用带有 C++ 扩展的 Eclipse。 它配备了创建和执行标准 C++ 程序所需的一切!

Eclipse 下载

Are you learning the standard C/C++ language? if the answer is yes then that syntax is concerning the Microsoft C++/CLI language...

look at : C++/CLI

Try to use Eclipse with C++ extension instead. It cames with all you need to create and execute a STANDARD C++ program!

Eclipse download

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