Extern keyword to define static data members and member functions, C ++

Does the C ++ standard provide a keyword externfor defining static data members and member functions (assuming the link matches)? For instance:

struct A
{
    static int a;    // external linkage
    void f();        // external linkage
};

extern int A::a;
extern void A::f() {}
+4
source share
1 answer

The keyword is externnot permitted as a storage class specifier for class members. From [dcl.stc] / 5:

[...] The specifier externcannot be used in the declaration of class members or function parameters. [...]

In addition, definitions are announcements, cf. [Basic.def] / 2:

A declaration is a definition, if only [rules].

, extern , , , .

+6

Source: https://habr.com/ru/post/1651153/


All Articles