Topic: friend keyword for operator+
Author: "mstampfer" <mstampfer@gmail.com>
Date: Mon, 8 Jan 2007 11:14:46 CST Raw View
The following class compiles fine. Why does removing the friend keyword
to the '+' operator cause the following compile time error in VC 8:
error C2804: binary 'operator +' has too many parameters? This seems
counterintuitive to me.
class Matrix
{
typedef float elemType;
public:
friend Matrix operator+(const Matrix &, const Matrix &);
// ...
private:
elemType _matrix[4][4];
};
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "=?iso-8859-1?q?Pedro_Lamar=E3o?=" <pedro.lamarao@gmail.com>
Date: Mon, 8 Jan 2007 13:39:16 CST Raw View
===================================== MODERATOR'S COMMENT:
I am approving this message as it is a follow-up, but this appears to be off-topic for comp.std.c++ and better suited to comp.lang.c++.moderated.
===================================== END OF MODERATOR'S COMMENT
On 8 jan, 15:14, "mstampfer" <mstamp...@gmail.com> wrote:
> The following class compiles fine. Why does removing the friend keyword
> to the '+' operator cause the following compile time error in VC 8:
> error C2804: binary 'operator +' has too many parameters? This seems
> counterintuitive to me.
>
> class Matrix
> {
> typedef float elemType;
> public:
> friend Matrix operator+(const Matrix &, const Matrix &);
> // ...
> private:
> elemType _matrix[4][4];
>
> };---
This declares that the free-function operator+ is a friend of class
Matrix.
operator+ declared as a free function takes two parameters.
If you take the friend keyword you are declaring the operator+ member
function of class Matrix.
operator+ declared as a member function takes one parameter.
--
Pedro Lamar o
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]