B
barbaros
Hi everybody,
I cannot understand why in the code included below the operator *
cannot be overloaded, once as a method then as a friend function. The
code compiles well, but when I uncomment the line "numeric
&operator*(const vector &b) const;" I get the following errors at line
15 (where the second, overloaded, operator is declared): "error:
declaration of 'operator*' as non-function" and "error: expected ';'
before '<' token".
My compiler is gcc version 4.3.3 (Debian 4.3.3-3).
What am I doing wrong ?
Thank you very much, Cristian Barbarosie
----------------------------------------------------
// VECTOR CLASS DECLARATION
template<typename numeric> class vector;
// DECLARATION OF FRIEND FUNCTIONS
template<typename numeric> int get_dim(const vector<numeric> &b);
template<typename numeric> vector<numeric> &operator*(numeric a, const
vector<numeric> &b);
// VECTOR CLASS DEFINITION
template<typename numeric> class vector {
public:
vector(int n);
numeric &operator()(int i) const;
// numeric &operator*(const vector &b) const;
friend int get_dim<numeric>(const vector<numeric> &b);
friend vector<numeric> &operator*<numeric>(numeric a, const
vector<numeric> &b);
private:
int size;
numeric *elements;
};
I cannot understand why in the code included below the operator *
cannot be overloaded, once as a method then as a friend function. The
code compiles well, but when I uncomment the line "numeric
&operator*(const vector &b) const;" I get the following errors at line
15 (where the second, overloaded, operator is declared): "error:
declaration of 'operator*' as non-function" and "error: expected ';'
before '<' token".
My compiler is gcc version 4.3.3 (Debian 4.3.3-3).
What am I doing wrong ?
Thank you very much, Cristian Barbarosie
----------------------------------------------------
// VECTOR CLASS DECLARATION
template<typename numeric> class vector;
// DECLARATION OF FRIEND FUNCTIONS
template<typename numeric> int get_dim(const vector<numeric> &b);
template<typename numeric> vector<numeric> &operator*(numeric a, const
vector<numeric> &b);
// VECTOR CLASS DEFINITION
template<typename numeric> class vector {
public:
vector(int n);
numeric &operator()(int i) const;
// numeric &operator*(const vector &b) const;
friend int get_dim<numeric>(const vector<numeric> &b);
friend vector<numeric> &operator*<numeric>(numeric a, const
vector<numeric> &b);
private:
int size;
numeric *elements;
};