#ifndef TINYVEC_HPP
#define TINYVEC_HPP
#include <iostream>
#include<iomanip>
using namespace std;
template<typename T_numtype, int N_length>
class TinyVector
{
protected:
T_numtype data[N_length];
public:
//////////////////////////////////////////////////////
// Constructor
//////////////////////////////////////////////
TinyVector() { }
~TinyVector() { }
TinyVector(const TinyVector<T_numtype,N_length>& x);
TinyVector(const T_numtype & initValue);
TinyVector(const T_numtype x[]);
TinyVector(const T_numtype & x0, const T_numtype & x1);
TinyVector(const T_numtype & x0, const T_numtype & x1, const T_numtype & x2);
double operator*(const TinyVector<T_numtype, N_length> &);
};
#include "TinyVector.cxx"
#endif
template<typename T_numtype, int N_length>
double TinyVector<T_numtype, N_length>::operator*(const TinyVector<T_numtype, N_length> & x)
{
double temp=0.0;
for (int i=0; i < N_length; ++i)
temp=temp+data[i]*x[i];
return temp;
}
Dear freinds:
I write a vector class template, but i can not compute a double number multiplies a vector, i have overload the * operator in the template, could you plese tell me how to resolve it.
Regards
ztdep
-8
Junior Poster in Training
Recommended Answers
Jump to PostIf you want to get the result of multiplying the entire contents of a TinyVector by a double and have the value returned as a double, (e.g.
double result = myTinyVector * 5.034;
) then this might work:double operator *(const double &x);
Which you could define as:
All 4 Replies
JasonHippy
739
Practically a Master Poster
NathanOliver
429
Veteran Poster
Featured Poster
mike_2000_17
2,669
21st Century Viking
Team Colleague
Featured Poster
ztdep
-8
Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.