Well I changed the code to Anons first post but the same error still pops up:
Code:
#include <iostream>
using namespace std;
//------------------------------
//Point class begin
//------------------------------
class Point
{
public:
Point(float f_x = 1.0, float f_y = 1.0, float f_z = 1.0);
~Point();
float getX() const;
float getY() const;
float getZ() const;
void setX(float X);
void setY(float Y);
void setZ(float Z);
Point& operator =(Point &p);
Point operator +(Point &p) const;
private:
float x, y, z;
protected:
};
Point::Point(float f_x, float f_y, float f_z)
{
x = f_x;
y = f_y;
z = f_z;
}
Point::~Point()
{
}
float Point::getX() const
{
return x;
}
float Point::getY() const
{
return y;
}
float Point::getZ() const
{
return z;
}
void Point::setX(float X)
{
x = X;
}
void Point::setY(float Y)
{
y = Y;
}
void Point::setZ(float Z)
{
z = Z;
}
Point& Point::operator =(Point &p)
{
setX(p.getX());
setY(p.getY());
setZ(p.getZ());
return *this;
}
Point Point::operator +(Point &p) const
{
Point outP;
outP.setX(getX() + p.getX());
outP.setY(getY() + p.getY());
outP.setZ(getZ() + p.getZ());
return outP;
}
//---------------------------
//Point class end
//---------------------------
int main (int argc, char * const argv[])
{
Point p1(4, 2, 1);
Point p2(6, 3, 8);
Point p3;
p3 = p2 + p1;
return 0;
}
The error just changed slightly because of the const:
error: no match for 'operator=' in 'p3 = Point:perator+(Point&) const(((Point&)(& p1)))'
Then I had a closer look at the warning it told me and come up with the following that also seems to work with no errors or warnings:
Code:
class Point
{
public:
Point(float f_x = 1.0, float f_y = 1.0, float f_z = 1.0);
~Point();
float getX();
float getY();
float getZ();
void setX(float X);
void setY(float Y);
void setZ(float Z);
Point operator =(Point *p);
Point operator +(Point &p);
private:
float x, y, z;
protected:
};
I'm only wondering is this correct C++? It looks alright to me.
And can anybody still tell me why my original code doesn't work in Xcode but will work in .NET?