此代码导致编译时错误:
#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
}
Run Code Online (Sandbox Code Playgroud)
编译错误:
C:\CodeBlocks\kool\praks3\vector.h|29|error: expected ')' before '<' token|
||=== Build finished: 1 errors, 0 warnings ===|
Run Code Online (Sandbox Code Playgroud)
以下是如何在类外定义构造函数:
template <unsigned short n>
Vector<n>::Vector(std::vector<float> crds) {
//also notice this ^^^^
}
Run Code Online (Sandbox Code Playgroud)