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 answers

does 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

Popular posts from this blog

javascript - THREE.js reposition vertices for RingGeometry -

javascript - I need to update the text of a paragraph by inline edit -

assembly - What is the addressing mode for ld, add, and rjmp instructions? -