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

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)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.