如何订购结构的向量
how order a vector of struct
im与C 一起工作,而我的论文则与NS3一起工作。因此,我想将struct的向量与STL函数进行排序,因此我将在矢量所在的位置发布标题文件,我将解释我想做什么。
#include "ns3/net-device.h"
#include "ns3/object.h"
#include "ns3/log.h"
#include <vector>
#include <stdint.h>
#include "miscellaneous.h"
namespace ns3 {
/**
* brief The UeRecord class is developed in order to store at the eNodeB
* all information (such as feedback cqi, mac address etc...) of a UE registered
* into that eNodeB. All UE records are managed by the UeManager class
*/
class UeRecord : public Object
{
public:
UeRecord ();
~UeRecord ();
/**
* brief CqiFeedbacks represents a list of CQI feedbacks
* sent by the UE. The downlink packet scheduler of
* the eNB uses these values to assign accordingly
* radio resources.
*/
/**
* brief a list of CQI feedbacks
*/
typedef std::vector<struct CqiFeedback> CqiFeedbacks;
/**
* brief Creates a ue record of the UE registered into the eNB
* param ue the pointer of the ue device
* param enb the pointer of the enb device
*/
UeRecord (Ptr<NetDevice> ue, Ptr<NetDevice> enb);
/**
* brief Set the UE of the record
* param ue the pointer of the ue device
*/
void SetUe (Ptr<NetDevice> ue);
/**
* brief Get the UE of the record
* returns the pointer of the UE
*/
Ptr<NetDevice> GetUe (void);
/**
* brief Set the eNB of the record
* param enb the pointer of the enb device
*/
void SetEnb (Ptr<NetDevice> enb);
/**
* brief Get the eNB of the record
* returns the pointer of the eNB
*/
Ptr<NetDevice> GetEnb (void);
/**
* brief Set CQI feedbacks of the registered UE
* param cqiFeedbacks a list of CQI feedback
*/
void SetCqiFeedbacks (CqiFeedbacks cqiFeedbacks);
/**
* brief Get CQI feedbacks of the registered UE
* returns a list of CQI feedback
*/
CqiFeedbacks GetCqiFeedbacks (void);
public:
friend bool operator > (const struct CqiFeedback &a, const struct CqiFeedback &b);
inline bool operator > (const struct CqiFeedback &a, const struct CqiFeedback &b)
{
if(a.m_cqi>b.mcqi) return true;
return false;
}
private:
Ptr<NetDevice> m_ue;
Ptr<NetDevice> m_enb;
CqiFeedbacks m_cqiFeedbacks;
};
结构是这个
struct CqiFeedback
{
/** the sub channel */
int m_subChannelId;
/** the cqi feedback */
int m_cqi;
};
我想按M_CQI参数以向量m_cqifeedbacks进行降序排序,标头文件中包含的结构杂项。因此,我试图用以前的方式超载操作员>,但我得到了此错误:
debug/ns3/ue-record.h:121: error: ‘bool ns3::UeRecord::operator>(const CqiFeedback&, const CqiFeedback&)’ must take exactly one argument
我不明白怎么了!愿你帮我,我试图阅读以前的讨论,但是我没有很好地意识到问题是什么....
this:
friend bool operator > (const struct CqiFeedback &a, const struct CqiFeedback &b);
inline bool operator > (const struct CqiFeedback &a, const struct CqiFeedback &b)
{
if(a.m_cqi>b.mcqi) return true;
return false;
}
应该是
friend bool operator > (const struct CqiFeedback &a, const struct CqiFeedback &b)
{
if(a.m_cqi>b.mcqi) return true;
return false;
}
将操作员声明为friend
,可以使您可以作为免费操作员实现 - 在这种情况下,请使用2个显式参数。因此,您已经声明了免费操作员,好的,但是随后您将成员操作员声明为带有2个参数的inline
,加上隐式this
,因此3个总参数,这是错误的。
另外,如果您想要成员操作员,请执行:
inline bool operator > (const struct CqiFeedback &b) const
{
if( m_cqi>b.mcqi ) return true;
return false;
}
,当然,您可以替换
if( m_cqi>b.mcqi ) return true;
return false;
用简单的
return m_cqi > b.mcqi
相关文章:
- 将结构向量排序为子组
- 访问存储在向量C++中的结构的多态成员
- NLOHMANN 的 JSON 库将数组转换为结构向量
- 在nlohmann json中,如何将嵌套对象的数组转换为嵌套结构的向量
- 如何在 c++ 中创建结构向量的映射
- 带unique_ptr的结构向量
- C++ - 如何在结构向量中找到结构体一个成员的最大值?
- C++,从文件读取到结构,然后读取到向量(结构被推入向量太多次,而不仅仅是一次)
- 将 int 映射到 C++ 中的向量结构
- 如何在 c++ 中的向量结构中使用结构向量
- 无法将值存储到向量结构中
- 无法将.CSV文件读取为代表向量结构的类
- MPI,C,派生类型,向量结构
- 向量结构的打印成员
- 在 c++ 中对向量<结构 S> 进行二分搜索?
- 不需要删除向量<结构A*>
- 在C++中循环向量结构<string>
- 将字符串放入字符串的向量结构中
- 共享内存中的向量结构
- 我的向量结构没有像预期的那样迭代