I have to create a class to represent a 2 dimensional vector. I need to include certain member functions such as a function to find magnitude of the vector, and one to find the dot product of that vector with another vector, and several others too. That's all fine. A stipulation of the problem is that I must include a constructor which can take cartesian form of the vector and a constructor which can take polar form of vector. Since this involves overloading the constructor the best solution I have come up with is to create the object with either doubles or floats so that the compiler can choose the correct constructor. This seems like a really bad idea. Is there a way I can get the compiler to choose the correct constructor without doing it using the precision? Here is a sample of my header file, there are many more member functions
in my .cpp file the object is created with either four doubles or four floats depending on which constructor I want to implement. There must be a better way.
p.s additionalArray is created for use in member function which require calculations with a second 2d vector.
Rather than constructor, you could have a helper function: Vector fromPolar( double radius, double angle );
If you absolutely need a constructor, then a dummy parameter may be necessary: Vector::Vector( double radius, double angle, void * )
The user would pass null: Vector foo( 7, 42, nullptr );