0

Hey folks. I am confused as to how i can make a constructor take zero - or lets say 3 arguments. If i do this in my main.cpp:

const Vector  v1;
   const Vector v2(1.0, 2.0, 3.0);

And this in my vector.cpp file:

Vector::Vector(double new_x, double new_y, double new_z)
{
  x = 0;
  y = 0;
  z = 0;
}

And then this in my vector.h file:

...
...
public:
        //Vector();
        Vector(double, double, double);
   
   };

I get an error saying this:

23 C:\Users\Tony\Documents\csci 241\Assign4\assign4.cpp no matching function for call to `Vector::Vector()'

THis makes sense as there is no constructor like this within my .h or .cpp file - so it doesnt know what to do. But i MUST have only one constructor, is this possible?

Hope you guys can help out again

Thanks in advance

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by dophine
0

as you provide a constructor, the compiler does not generate a default constructor which takes no parameter for you.

so if you want a constructor to take zero parameter, then you must define it.
or you can try this to provide default value

Vector::Vector(double new_x=2.0, double new_y=2.0, double new_z=2.0)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.