What is the best way to indicate that a double value has not been initialized?

前端 未结 9 1944
萌比男神i
萌比男神i 2020-12-22 06:26

I have a class CS which is to represent the co-ordinate system in 3D i.e.(x, y, z)

class CS
{
  private:
        double x;
        double y;
        double z         


        
9条回答
  •  旧巷少年郎
    2020-12-22 07:04

    I want that the user can create a CS (0, 0, 0). In the constructor i want to initialise the address of x, y & z to NULL. this is to differentiate between the user defined (0, 0, 0) & the default value. I am creating the objects of CS dynamically, so there is no point in using the following code:

    This is the problem. Firstly, default value? What default value? Why should there be a default value? That's wrong. And secondly, it's fundamentally impossible for you to change the address of any variable.

    What you want cannot be done and even if it could, it would be a horrendously bad idea.

提交回复
热议问题