Correct place to initialize class variables?

前端 未结 5 1914
盖世英雄少女心
盖世英雄少女心 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:05

    A class variable must be marked as "static". If your variable is an instance variable and not a class variable you must initialize it in the constructor or other method.

提交回复
热议问题