Declaring class objects in a header file

前端 未结 3 1847
渐次进展
渐次进展 2021-01-12 05:11

Greetings everyone.

I seem to be snagging on a fundimental but I cant find the solution anywhere. Anywho, will go ahead and explain.

I have a program consist

3条回答
  •  有刺的猬
    2021-01-12 05:47

    You can also have the following line of code in your header file:

    static SA Obj1, Obj2;
    

    This will create only 1 instance of each object at run time and prevent redefinitions. However, keep in mind that all files that include the .h file will be using the same instance of those two objects so you will need to be careful when you are accessing them.

提交回复
热议问题