Reputation: 16561
This code results in a compile-time error:
#include <iostream>
#include <vector>
#include <cmath>
template <unsigned short n>
class Vector {
public:
std::vector<float> coords;
Vector();
Vector(std::vector<float> crds);
float distanceFrom(Vector<n> v);
template <unsigned short m>
friend std::ostream& operator <<(std::ostream& out, const Vector<m>& v);
};
template <unsigned short n>
Vector<n>(vector<float> crds) { // HERE IS ERRRO
}
Compile error:
C:\CodeBlocks\kool\praks3\vector.h|29|error: expected ')' before '<' token|
||=== Build finished: 1 errors, 0 warnings ===|
Upvotes: 1
Views: 179
Reputation: 91320
template <unsigned short n>
Vector<n>::Vector(vector<float> crds) {
}
EDIT: As others mentioned, if you're not using namespace std;
you also need std::vector<float>
Upvotes: 4
Reputation: 62333
Should it be this?
template <> Vector<unsigned short>::Vector(Vector<float> crds)
{
// BLAH
}
It looks to me like you've got confused on template specialisation.
Upvotes: 0
Reputation: 361802
Here is how you should define the constructor outside the class:
template <unsigned short n>
Vector<n>::Vector(std::vector<float> crds) {
//also notice this ^^^^
}
Upvotes: 8
Reputation: 1004
Vector::Vector(constructor args) You just forgot to scope the constructor
Upvotes: 0