C++ static member functions and variables

前端 未结 6 429
北恋
北恋 2021-01-31 11:40

I am learning C++ by making a small robot simulation and I\'m having trouble with static member functions inside classes.

I have my Environment class defined like this:<

6条回答
  •  星月不相逢
    2021-01-31 12:23

    A static method cannot access instance variables. If you want to access instance variable remove static from the method. If those values can be the same through all robot instances then make them static variables and the method can remain static.

提交回复
热议问题