这是本网站的第一个问题,我想按获得的积分排序,团队排名,有任何错误,但短路不起作用。 我希望你的帮助能够克服这个问题
Team.h
ptr = (int*) malloc(100 * sizeof(int))
Team.cpp
class Team
{
private:
std::string t_name;
int t_rank;
public:
int t_points;
Team(std::string name);
~Team();
void win();
void show(std::ostream &Flux)const;
};
std::ostream& operator<<(std::ostream &Flux, Team const &B);
bool operator<(Team const& A,Team const& B);
的main.cpp
Team::Team(string name): t_name(name), t_points(0) {}
void Team::win()
{
t_points+=3;
}
void Team::show(std::ostream &Flux)const
{
Flux << t_name;
}
std::ostream& operator<<(std::ostream &Flux, Team const &B)
{
B.show(Flux);
return Flux;
}
bool operator<(Team const& A,Team const& B){
return A.t_points < B.t_points;
}
我编辑了我的文件以添加您提供的信息,但仍然没有回应m问题,所以我重新发布所有内容并等待更多帮助
答案 0 :(得分:1)
由于vector<Team*>
存储指针,您需要重载operator<(const Team*, const Team*) operator
,如下所示:
bool operator<(const Team* left, const Team* right) {
return left->whatever < right->whatever;
}
答案 1 :(得分:0)
这完全没问题。但仅当SELECT C.OCD, COUNT(*) AS USED FROM DRAFT D
JOIN STKRNG S ON S.DFTACCT_CANUM = D.DFTACCT_CANUM
JOIN DFACCT DA ON S.DFTACCT_CANUM = DA.DFTACCT_CANUM
JOIN CMPNT C ON CMPNT.OCD = DA.OWNG_OCD
WHERE D.DRFT_SEQ_NUM >= (SELECT MIN(S.STK_STRT_SEQ_NUM) FROM STKRNG S
WHERE D.DFTACCT_CANUM = S.DFTACCT_CANUM AND S.RANGE_USED_SW = 'N')
AND D.DRFT_SEQ_NUM <= (SELECT MAX(S.STK_END_SEQ_NUM) FROM STKRNG S WHERE
D.DFTACCT_CANUM = S.DFTACCT_CANUM AND S.RANGE_USED_SW = 'N')
AND S.STK_TYP = 'R'
AND S.RANGE_USED_SW = 'N'
AND C.ST = 'FL'
GROUP BY C.OCD;
不是a_
:
private
将#include <algorithm>
#include <iostream>
#include <vector>
class A {
public:
A(size_t const& a) : a_(a) {};
~A(){};
//private:
size_t a_;
};
bool operator<(A const& left, A const& right) {
return left.a_ < right.a_;
}
int main() {
std::vector<A*> v;
v.push_back(new A(10));
v.push_back(new A(6));
v.push_back(new A(8));
for(auto const& a : v) {
std::cout << a->get() << std::endl;
}
std::sort(v.begin(),v.end());
for(auto const& a : v) {
std::cout << a->get() << std::endl;
}
}
作为成员实施,这也将得到解决:
operator<
然后,bool operator<(A const& other) {
return a_ < other.a_;
}
可以是私有的。