Unresolved external symbol on static class members

后端 未结 5 1394
温柔的废话
温柔的废话 2020-11-22 02:04

Very simply put:

I have a class that consists mostly of static public members, so I can group similar functions together that still have to be called from other clas

5条回答
  •  终归单人心
    2020-11-22 02:53

    If you are using C++ 17 you can just use the inline specifier (see https://stackoverflow.com/a/11711082/55721)


    If using older versions of the C++ standard, you must add the definitions to match your declarations of X and Y

    unsigned char test::X;
    unsigned char test::Y;
    

    somewhere. You might want to also initialize a static member

    unsigned char test::X = 4;
    

    and again, you do that in the definition (usually in a CXX file) not in the declaration (which is often in a .H file)

提交回复
热议问题