c++ - Why is class name used before the variable name together with "::"? -


i have found code construct, have never seen before , don't know how called. can explain me? not able find via google nor in forum.

module.cpp

namespace nsmodule {     cmodule cmodule::instance;    //global in namespace } 

module.hpp

namespace nsmodule {    class cmodule    {        public:            /* methods , such stuff */         private:            static cmodule instance;    } } 

why there class before variable :: ?

cmodule cmodule::instance; 

i change title , specify question, when know how called.

what looking @ known static class member:

static members of class not associated objects of class: independent objects static storage duration or regular functions defined in namespace scope, once in program. static keyword used declaration of static member, inside class definition, not definition of static member:

class x { static int n; }; // declaration (uses 'static') int x::n = 1;              // definition (does not use 'static') 

as can see in example, when variable marked static, defined outside class (unless integral types such int). thus, in code, static cmodule instance; being defined outside class, definition calls default constructor of class cmodule follows:

  cmodule  cmodule::  instance; //type     class name variable name  

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -