gpt4 book ai didi

c++ - C++ 中有 "attribute"关键字吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:04:33 24 4
gpt4 key购买 nike

也许我错过了什么,但我想知道以下几点:

Mozilla Developer Pages about Coding Guidelines ,我阅读了以下内容:

Whenever you are retrieving or setting a single value without any context, you should use attributes. Don't use two methods when you could use one attribute. Using attributes logically connects the getting and setting of a value, and makes scripted code look cleaner.

This example has too many methods:

 interface nsIFoo : nsISupports {
long getLength();
void setLength(in long length);
long getColor();
};

The code below will generate the exact same C++ signature, but is more script-friendly.

interface nsIFoo : nsISupports {
attribute long length;
readonly attribute long color;
};

我想到的是属性long length。我假设此语法会自动创建 getter/setter 方法。

  • 但是那是标准的 C++ 吗?
  • 这是一些特定于 mozilla 的东西吗?
  • 这是在哪里定义的?

最佳答案

Mozilla 使用一种称为 IDL(接口(interface)定义语言)的语言来定义在多语言上下文中使用的对象的接口(interface),例如 C++ 和 JavaScript。它编译成这两种语言的代码,因此允许从事该项目的开发人员以他们喜欢的多种语言对其接口(interface)进行单一定义。所以不,这不是标准的 C++ 代码;这是完全不同的东西。

相关说明,interface 和 readonly 也不是 C++ 关键字。 :-)

关于c++ - C++ 中有 "attribute"关键字吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4983927/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com