C++: Static keyword in non-class context? -
C++: Static keyword in non-class context? -
this question has reply here:
the static keyword , various uses in c++ 8 answersdoes static create sense below (i'm coming java background)? compiles, what's convention/standard?
#ifndef func_h #define func_h int func(const int& x, const int& y); //cache used values const static int = func(2, 0); const static int b = func(3, 0); #endif // func_h
in such context, static keywords means file scope, in c. not want in public header.
want want extern, in header file:
extern const int a; extern const int a; it declare 2 global variables. you'll need definition, in .cpp file:
const int = 42; const int b = 43; about file scope, means visibility of such declaration limited file in declared. linker won't generate public symbol this. if utilize in header file, different declaration issued in each file header included.
c++ static
Comments
Post a Comment