-
-
-
- We can access a static member directly through the scope operator.
-
in general, we may not initialize astatic member inside the class. Instead, we must define and initialize each staticdata member outside the class body.
-
Ordinarily, class static members may not be initialized in the class body. However,we can provide in-class initializers for static members that have const integral type and must do so for static members that are constexprs of literal type
-
Even if a const static data member is initialized in the class body, that member ordinarily should be defined outside the class definition.
class Bar { public: // ... private: static Bar mem1; // ok: static member can have incomplete type Bar *mem2; // ok: pointer member can have incomplete type <span style="font-family: Arial, Helvetica, sans-serif;">Bar mem3; // error: data members must have complete type };</span>
// for each file passed to the program for (auto p = argv + 1; p != argv + argc; ++p) { ifstream input(*p); // create input and open the file <span style="font-family: Arial, Helvetica, sans-serif;">if (input) { // if the file is ok, ''process'' this file </span><span style="font-family: Arial, Helvetica, sans-serif;"><span> </span>process(input); } else </span><span style="font-family: Arial, Helvetica, sans-serif;">cerr << "couldn't open: " + string(*p); </span><span style="font-family: Arial, Helvetica, sans-serif;">} // input goes out of scope and is destroyed on each iteration</span>
-
-
7.6 Static Class Members
最新推荐文章于 2023-04-22 22:24:12 发布