Class containing Constants of std::string

前端 未结 2 1290
一生所求
一生所求 2021-01-26 04:14

So I\'m currently working on a school-project with C++, which I\'m not really familiar with. I would like to create a class, containing all my constants (string,int,double,own c

2条回答
  •  春和景丽
    2021-01-26 04:36

    You should declare your data members in your header file, but the definitions should be placed in the source file, like this for example:

    const std::string Reference ::earthPath = "E:\\Development\\C++\\Material\\terrain\\deep_sea.tga";
    

    Read more in: Static Data Member Initialization.


    PS: Classes do not use to expose into public scope their data members. Getter and Setter functions are used instead, while the data members are not in public scope. If all you need is your data members, then a namespace could be a better design choice, than a class.

提交回复
热议问题