为什么不能成功排序# Programming - 葵花宝典
m*o
1 楼
我写的这个代码是为了将类对象和对象里的数组进行双重排序,但不知道为什么对象不
能成功排序:
#include
using namespace std;
class c_array {
friend int sum(c_array &a);
public:
c_array(int s): size(s) { a = new int[size]; }
int& operator[](int i);
int get_size() { return size; }
bool operator < (c_array& x);
//private:
int size;
int *a;
};
int sum(c_array& a){
int result = 0;
int size = a.get_size();
for ( int i = 0; i < size; i++ )
result += a[i];
return result;
}
bool
能成功排序:
#include
using namespace std;
class c_array {
friend int sum(c_array &a);
public:
c_array(int s): size(s) { a = new int[size]; }
int& operator[](int i);
int get_size() { return size; }
bool operator < (c_array& x);
//private:
int size;
int *a;
};
int sum(c_array& a){
int result = 0;
int size = a.get_size();
for ( int i = 0; i < size; i++ )
result += a[i];
return result;
}
bool