Correct place to initialize class variables?

前端 未结 5 1962
盖世英雄少女心
盖世英雄少女心 2021-01-31 04:28

Where is the correct place to initialize a class data member? I have the class declaration in a header file like this:

Foo.h:

class Foo {
private:
    in         


        
5条回答
  •  我在风中等你
    2021-01-31 05:02

    You're attempting to initialize an instance member via a static initialization construct. If you want this to be a class level variable (static) then precede the variable with the static keyword.

    class Foo {
    private:
      static int myInt;
    };
    

提交回复
热议问题