#ifndef VECTOR2_HPP
#define VECTOR2_HPP
#include <cmath>
#include <utility>
#include <vector>
#ifndef M_PI
#define M_PI 3.1415926
#endif
#define DEGTORAD(Deg) ((Deg * M_PI) / 180.0)
#define RADTODEG(Rad) ((180.0 * Rad) / M_PI)
/*
* Euclidian vector with many useful member functions
*/
template <class T>
class Vector2
{
public:
Vector2()
{
magnitude = 0;
direction = 0;
}
Vector2(T start_magnitude, T start_direction)
{
magnitude = start_magnitude;
direction = start_direction;
}
~Vector2()
{
}
T magnitude;
T direction;
/*
* Returns an std::pair<T, T> of the coordinates of the
* point_numth point on the vector
*/
std::pair<T, T> get_point(int point_num)
{
std::pair<T, T> point;
point.first = std::sin(DEGTORAD(direction)) * magnitude;
point.second =
std::cos(DEGTORAD(direction)) * magnitude;
return point;
}
/*
* Returns an std::vector<std::pair<T, T>>. Each pair contains
* the coordinates of a point on the vector, up to num_points
* points (including (0, 0))
*/
std::vector<std::pair<T, T>> get_points(int num_points)
{
std::vector<std::pair<T, T>> points;
for (int i = 0; i < num_points; i++)
{
std::pair<T, T> point = get_point(i);
points.push_back(point);
}
return points;
}
};
#endif // VECTOR2_HPP
My errors:
1 2 3 4 5 6 7 8 9
Vector2.hpp:56: error: a function call cannot appear in a constant-expression
Vector2.hpp:56: error: ‘>>’ should be ‘> >’ within a nested template argument list
Vector2.hpp: In member function ‘std::vector<std::pair<_ForwardIterator, _ForwardIterator>, std::allocator<std::pair<_ForwardIterator, _ForwardIterator> > > Vector2<T>::get_points(int)’:
Vector2.hpp:58: error: ‘coords’ was not declared in this scope
Vector2.hpp:58: error: ‘>>’ should be ‘> >’ within a nested template argument list
Vector2.hpp:58: error: redeclaration of ‘std::vector<std::pair<_ForwardIterator, _ForwardIterator>, std::allocator<std::pair<_ForwardIterator, _ForwardIterator> > > coords’
Vector2.hpp:58: error: ‘<typeprefixerror>coords’ previously declared here
main.cpp: In function ‘int main()’:
main.cpp:8: error: ‘>>’ should be ‘> >’ within a nested template argument list
I really don't understand what's prompting the errors. If anybody could give me some help, I'd really appreciate it. (I'm compiling with gcc)
I don't think the errors could be any more explicit.
std::vector<std::pair<T, T>> is invalid. It's
std::vector<std::pair<T, T> >
>> is an operator, remember?
Oh, wow, that was amazingly simple.
I have a habit of only looking at the first error message, because the subsequent ones tend to be caused by the first message, and go away after the first one is fixed. So, I didn't but 2 and 2 together and see the the function call it was talking about must have been the >> operator.