Incorrect values are being stored for Vector3d

I'm getting incorrect values stored into my Vector3D. In the program it asks for the original value and I'm getting a long -4.3423432523....... number even though I have in my default constructor the values set to zero. Can anyone tell me what the problem is?
Without seeing the code it is difficult to say anything.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Vector3D
{
  private:
      

  public:
      float x,y,z;
   Vector3D Vector3d (float xVector= 0.0, float yVector =0.0, float zVector = 0.0);
   void Read();
   void Print() const;
   const bool operator == (const Vector3D rhs) const;
   const Vector3D operator * (const Vector3D rhs) const;
   const bool operator != (const Vector3D rhs) const;
   const Vector3D operator + (const Vector3D rhs) const;
   const Vector3D operator - (const Vector3D rhs) const;
   const float operator % (const Vector3D rhs) const;
   const Vector3D operator = (const Vector3D rhs) const;
   const Vector3D operator * (const int rhs) const;
   

   float magnitude ();

   float normalized ();


   friend ostream& operator<< ( ostream& ostr, const Vector3D& myVector );

   friend istream& operator>> ( istream& istr, Vector3D& myVector );
};


1
2
3
4
5
6
int main()
{
    Vector3D  x,y,z;

    cout << "Initial value of x: " << x << endl;
    cout << "Initial value of y: " << y << endl;


I'm not sure why it's giving me those outragous numbers since my default constructor sets them all to zero.
I do not see the definition of the default constructor and of the operator << .
Last edited on
closed account (zb0S216C)
thechad90000 wrote:
Vector3D Vector3d (float...

...is not a constructor. This is a function called Vector3d that returns an anonymous Vector3D object, and takes 3 float arguments. This is a constructor:

1
2
3
4
5
6
7
8
9
class Vector3D
{
    public:
        Vector3D(float InitX = 0.0F, float InitY = 0.0F, float InitZ = 0.0F);
};

Vector3D::Vector3D(float InitX, float InitY, float InitZ)
    : X(InitX), Y(InitY), Z(InitZ)
{ }

Wazzak
You point that out actually helped me because I didn't have a default constructor definition in the .cpp file. Thanks.
Last edited on
As was said it si a function not a constructor. And it is only declaration of the function that has default arguments. There is no its definition. So maybe it sets something to zero but I do not know.:)
Last edited on
I really do appreciate the help. I've got it figure out now. Thanks a ton.
Topic archived. No new replies allowed.