【发布时间】:2016-09-05 06:38:54
【问题描述】:
这里我有来自类ColVol 的对象数组,它用int 定义了三维点-类型颜色和体积(int 也是)。如果颜色在 [1,10] 之间,任务是按体积对数组进行排序。错误是the expression must be modifiable lvalue?Here 只是函数的声明。我不知道什么类型的排序在这里最好,为什么当tempvariable 是int, object.get_method() (在这种情况下数组是f[] and f[i].get_volume()isint`时给我这个错误?它们是同一类型。
template<class T> class Point3 {
T x, y, z;
public:
Point3();
void print() const;
};
template<class T, class U> class ColPoint3 :public Point3<T> {
U color;
public:
ColPoint3();
void print() const;
};
template<class T, class U, class V> class ColVol :public ColPoint3<T, U> {
V volume;
public:
ColVol();
void print() const;
V get_volume() {
return volume;
}
};
int main() {
const int n = 2;
ColVol<double, int, int> *f;
f = new ColVol<double, int, int>[n];
for (int i = 0; i < n; i++) {
f[i];
}
int temp;
for (int k = 0; k < n; k++) {
if (f[k].get_color() >= 1 || f[k].get_color() <= 10) {
for (int i = 0; i < n - 1; i++)
for (int j = 0; j < n - i + 1; j++)
if (f[j].get_volume() > f[j + 1].get_volume()) {
temp = f[j].get_volume();
f[j].get_volume() = f[j+1].get_volume();
f[j + 1].get_volume() = temp;
}
}
}
}
【问题讨论】:
-
对于带颜色的 3D 点,“体积”是什么意思?
标签: c++ arrays sorting templates