I have the code:
// class declaration
class Vector3D;
// class declaration and definition
class Point3D {
// ...
// function declaration (only needs class declarations)
Point3D operator+(const Vector3D &);
};
// class definition
class Vector3D {
// ...
};
// function definition (needs class definitions)
inline Point3D Point3D::operator+(const Vector3D &vector) {
// ...
}
But I get errror:
‘Graphic::Point3D::operator +’ : redefinition; different type modifiers
The code in your question is well-formed. The Visual C++ 2012 Release Candidate accepts the code without error (I mention this because the text of your error is identical to that of Visual C++ error C2373).
Either your compiler has a bug, or the code you present in your question is not the same as the code you are compiling.
In any case: an
operator+does not need to be a member function. It would be simpler to use a nonmember function (or two, to handle different operand orderings):If you do keep your
operator+member function(s), they should be const-qualified so that they can be called with a const-qualified left-hand argument: