### a problem with template

Hello, I'm doing a programme for vector calculation. I want to do it with template and classe. All operations work accept beside calculation vector length. Can anybody help me? I don't know what is wrong and how should it be written. Here is an minimum example.

#include <cstdlib>
#include <iostream>
#include <math.h>

using namespace std;

template <class t>
class vector
{
template <class tt>
friend const vector<tt> operator + (const vector<tt>& w1, const vector<tt>& w2);

private:
t x,y,z;
public:
vector()
{
x=0;
y=0;
z=0;
}
vector(const t& p1, const t& p2, const t& p3)
{
x=p1;
y=p2;
z=p3;
}
void display()
{
cout<<"["<<x<<","<<y<<","<<z<<"]"<<endl;
}
t length(const vector<t>& w1)
{
t temp;
temp=sqrt(w1.x*w1.x+w1.y*w1.y+w1.z*w1.z);
return temp;
}
};
template <class t>
const vector<t> operator + (const vector<t>& w1, const vector<t>& w2)
{
vector<t> temp;
temp.x=w1.x+w2.x;
temp.y=w1.y+w2.y;
temp.z=w1.z+w2.z;
return temp;
}

int main()
{
float a,ax,ay,az;
cin>> ax >> ay >>az;
vector<float> w1(ax,ay,az);

cin>> ax >> ay >>az;
vector<float> w2(ax,ay,az);

vector<float> w3;
w3=w1+w2;
cout<<"sum of w1 i w2 "<<endl;
w3.display();
cout<<endl;
cout<<"length w1: "<<w1.length()<<" length w2: "<<w2.length()<<endl;
system("pause");
return 0;
}

Other operation (substraction, cross product) are defined in a similar way as +. Template <class t> class vector... is more complex (it contain more function), but with this minimum working example working correct I think that I will manage to modify my programme.
 ``1234567`` ``````template t length() { t temp; temp=sqrt(x*x+y*y+z*z); return temp; } ``````