Is there a "attribute" keyword in C ++?

Maybe I missed something, but I'm interested in the following:

On the Mozilla developers page about coding rules, I read the following:

Whenever you retrieve or set a single value without any context, you should use attributes. Do not use two methods when you could use one attribute. Using attributes logically connects getting and setting a value and makes viewing the script cleaner.

There are too many methods in this example:

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

The code below will have the same C ++ signature, but more script friendly.

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

I am thinking of attribute long length . I assume that this syntax automatically creates getter / setter methods.

  • But is this standard C ++ in any way?
  • Is this some specific material for mozilla?
  • Where is this defined?
+6
c ++ attributes
source share
3 answers

Mozilla uses a language called IDL (Interface Definition Language) to define interfaces for objects that are used in multilingual contexts such as C ++ and JavaScript. It compiles into code in these two languages ​​and, therefore, allows developers working on a project to have a single definition for their interfaces in any number of languages ​​that they would like. No, this is not standard C ++ code; it is something completely different.

In the corresponding note, the interface and readonly are also not C ++ keywords .:-)

+12
source share

This coding guide applies to IDL, not C ++, so no, attribute not part of C ++. The guidelines accept the C ++ signatures that IDL generates.

+5
source share

it

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

is I nterface D escription L anguage (used for C ++ - Javascript interop). Mozilla has a tool that generates C ++ code for this, with the usual getter and setter methods.

C ++ itself does not have the attribute keyword.

+3
source share

All Articles