gpt4 book ai didi

c++ - 声明类和继承的冲突

转载 作者:搜寻专家 更新时间:2023-10-31 01:58:14 27 4
gpt4 key购买 nike

我有一个类 PointVector Vector 继承自 Point 并且 Point 使用 Vector 作为友元 我有一个 cpp 文件..我该如何解决这个冲突。 我不想使用头文件 我的代码是:

 class Vector:Point
{
//something
};

class Point
{
public:
friend class Vector;

double x;
double y;
Vector Point::operator-( Point Q) // Vector diff of Points
{
Vector v;
v.x = x - Q.x;
v.y = y - Q.y;
v.z = z - Q.z;
v.dimn = max( dimn, Q.dim());
return v;
}

Point Point::operator+( Vector v) // +ve translation
{
Point P;
P.x = x + v.x;
P.y = y + v.y;
P.z = z + v.z;
P.dimn = max( dimn, v.dim());
return P;
}

Point Point::operator-( Vector v) // -ve translation
{
Point P;
P.x = x - v.x;
P.y = y - v.y;
P.z = z - v.z;
P.dimn = max( dimn, v.dim());
return P;
}

Point& Point::operator+=( Vector v) // +ve translation
{
x += v.x;
y += v.y;
z += v.z;
dimn = max( dimn, v.dim());
return *this;
}

Point& Point::operator-=( Vector v) // -ve translation
{
x -= v.x;
y -= v.y;
z -= v.z;
dimn = max( dimn, v.dim());
return *this;
}
};

最佳答案

尝试前向声明-

class Vector;
class Point { ... }

关于c++ - 声明类和继承的冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4363130/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com