No, you cannot propagate static
ness in the sense you ask. Incidentally, you could also ask the same thing about const
:
int foo(int x) { return bar(x) + 1; } // Infer that foo is const because bar is
C++ specifiers are meant to convey intent about the interface, on which users can rely even if the implementation changes:
static int foo(x); // This method does not require an object
int foo(x) const; // This method will not modify the object
In case - through templates, for example - the implementation may vary, your interface must reflect the lowest common denominator. For const
, for example, methods need to be non-const
. For static
, which is your question, you cannot declare static
.
Note that this is not a huge imposition. Even if a method is static
, you can still call it using with object semantics. So, in your case, you'll have to just use object semantics. In particular, regarding your clarification in the comments
If allocator is static then container doesn't need to hold it's pointer. So decorators must preserve staticness.
note that decorators can also not preserve static
ness, because containers can hold pointers in any case, and call them via object notation, regardless of their const
ness.