c++ Defining static class function -


i have c++ code:

static class uenum* eviewmodeindex_staticenum() {     static class uenum* singleton = null;     if (!singleton)     {         ...     } return singleton; } 

this code part of game engine compiles , runs correctly. however, not understand meaning of "class" in first , third line.

when have class a, can use class a declare variable, return type, or argument type. same using a same purpose. under circumstances, use of class redundant legal.

class {    // ... };  void foo() {    // create instance of using simple syntax.    f1;     // create instance of using redundant class keyword    // use of class redundant legal.    class f2; } 

however, in cases, necessary use class/struct keyword disambiguate function of same name class/struct name.

from c++11 standard:

9.1 class names

...

a class declaration introduces class name scope declared , hides class, variable, function, or other declaration of name in enclosing scope (3.3). if class name declared in scope variable, function, or enumerator of same name declared, when both declarations in scope, class can referred using elaborated-type-specifier (3.4.4). [ example:

struct stat {      // ...   };   stat gstat;   // use plain stat                // define variable   int stat(struct stat*);   // redeclare stat function  void f() {    struct stat* ps;        // struct prefix needed                            // name struct stat    stat(ps);               // call stat() } 

— end example ]


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -