I now understand why a static class can be used without creating an object, because its value is fixed regardless of whether you create it or not.

I now understand why a static class can be used without creating an object, because its value is fixed regardless of whether you create it or not.

It also reminds me that the java teacher said that abstract classes have nothing to do with instances, so there is no need to instantiate them.

It should also be here that the value of this quantity here is fixed, and has nothing to do with the object. The value is fixed regardless of whether the object is created or not. The static class just cannot be changed.

So now I understand why a static class does not need to create an object to directly call a class member with the class name! ! ! ! ! ! Once you understand this essence, you can understand it, and you don't have to memorize it by rote! ! ! ! ! After you understand this essence, you can use it flexibly.

It really has nothing to do with the specific instance, so there is no need to instantiate it.

And some classes need to be instantiated. For example, the variables in the class are names and student IDs. This must be instantiated, right? When instantiating, assign specific values ​​to it, so a constructor is needed! ! ! ! ! A lot of things will be understood at once! ! ! ! ! ! !

And this kind of double colon is used when referring to the class name without creating an object.

Let me speculate whether this can be done for constant references in the class.

 

 

 

This is also the inspiration for me that the quantities in the msg file in ROS have been assigned. (Later, it is determined that it will automatically become an enumeration type after compilation, and the enumeration type in the class is a static member variable)

 

The variables in the message types used for object creation should not be assigned values! ! ! ! ! ! ! ! ! ! ! !

Or that is, you can use the value that has been assigned in it, you can directly use it without creating an object, and you need to create an object with the amount that has no value in it! ! ! ! ! ! You can answer my question, why don’t the variables in the class need to be created and then referenced.

https://blog.csdn.net/sinat_16643223/article/details/114503233

 

 

Like this

https://gitee.com/maxibooksiyi/Prometheus/blob/master/Modules/control/src/px4_sender.cpp

In fact, there should be no problem with the following kind of object reference creation by me, but it may be superfluous. Because it really has nothing to do with the specific instance, it does not need to be instantiated.

https://gitee.com/maxibooksiyi/Prometheus/blob/master/Modules/common/msgs/msg/DroneState.msg

 

https://gitee.com/maxibooksiyi/Prometheus/blob/master/Modules/common/msgs/msg/ControlCommand.msg

This armed called through the object is indeed an unassigned quantity

https://gitee.com/maxibooksiyi/Prometheus/blob/master/Modules/control/src/px4_sender.cpp

 

 

 

https://blog.csdn.net/weixin_40539125/article/details/84112472

 

https://blog.csdn.net/a1809032425/article/details/101644762

 

Taken from "C++ primer"

 

These three methods in opencv are static methods. It should be easy to understand now, because they really have nothing to do with specific objects. It makes sense for others to set such rules as static methods.

https://blog.csdn.net/sinat_16643223/article/details/107660715

Guess you like

Origin blog.csdn.net/sinat_16643223/article/details/114539707