When all does comma operator not act as a comma operator?

后端 未结 5 1927
别那么骄傲
别那么骄傲 2020-12-20 16:38

If you see this code,

class A{
public:
    A(int a):var(a){}
    int var;
};

int f(A obj) {
    return obj.var;
}

int main() {
    //std::cout<

        
5条回答
  •  再見小時候
    2020-12-20 17:34

    I did a search over the draft Standard. Basically, in the grammar the -list productions are the ones that have commas in them to separate different items. The following results are C++03 specific. In C++0x, expression-list directly delegates to initializer-list because in C++0x brace lists can occur in function and constructor arguments likewise.

    • expression-list For function/constructor arguments (including functional casts)
    • enumerator-list The list of items of an enumeration
    • init-declarator-list The different names declared in one declaration

      Example:

      int a, b;
      
    • parameter-declaration-list The parameter declaration list (surprise!) of a function
    • initializer-list List similar to expression-list, but can include braced expression lists. Used for aggregate initialization (initializing arrays or structs)
    • member-declarator-list Similar to the init declarator list, but for member declarations in classes.

      Example:

      struct A { int a, b; };
      
    • base-specifier-list List of base-classes of a class.
    • mem-initializer-list List of the initializers for members

      Example:

      struct A { A():a(0), b(0) { } int a; int b; };
      
    • template-parameter-list List of template parameter declarations.
    • template-argument-list List of template arguments passed to a template.
    • type-id-list List of types for exception specifications

      Example:

      void f() throw(int, bool) { }
      

    There is an identifier-list for macro parameters too, which i haven't got in that list because it's really part of the preprocessor grammar.

提交回复
热议问题