How to initialize private static members in C++?

后端 未结 17 2309
忘掉有多难
忘掉有多难 2020-11-21 07:04

What is the best way to initialize a private, static data member in C++? I tried this in my header file, but it gives me weird linker errors:

class foo
{
           


        
17条回答
  •  时光取名叫无心
    2020-11-21 07:15

    I just wanted to mention something a little strange to me when I first encountered this.

    I needed to initialize a private static data member in a template class.

    in the .h or .hpp, it looks something like this to initialize a static data member of a template class:

    template
    Type ClassName::dataMemberName = initialValue;
    

提交回复
热议问题