c++ - Passing Map by Reference Conflicting Messages
问题描述
I have the following class header (modified for brevity):
#include <map>
#include <vector>
#include <string>
class ComMon
{
//Properties
public:
typedef std::map<int, std::map<int, int>> CMD_Map;
//<Level_Number, <Member_ID, Role_ID (default=0)>>
static int Add_Platform(int LevelNO,int MemberID, int RoleID,CMD_Map *CurrentMap);
......
}
And the associated cpp file (modified for brevity):
int ComMon::Add_Platform(int LevelNO, int MemberID, int RoleID, ComMon::CMD_Map *CurrentMap)
{
if (CurrentMap->empty) {
std::map<int, int> InnerMap;
InnerMap.insert_or_assign(MemberID, RoleID);
CurrentMap->insert_or_assign(LevelNO, InnerMap);
}
else {
//see if Level is in Map
int Levels = (CurrentMap->size);
if (Levels >= LevelNO) {
//get inner list for the level
CurrentMap[LevelNO].insert_or_assign(MemberID,RoleID);
}
else {
//add new level
std::map<int, int> InnerMap;
InnerMap.insert_or_assign(MemberID, RoleID);
CurrentMap[LevelNO].insert_or_assign(LevelNO, InnerMap);
}
}
return 0;
}
When I compile, I get the following error message:
Error C3867 'std::_Tree>::empty': non-standard syntax; use '&' to create a pointer to member
With the error pointing to this:
if (CurrentMap->empty) {
If I alter the line to this:
if (&CurrentMap->empty) {
and try to compile, I get the following error message:
'&': illegal operation on bound member function expression
Again, pointing to the same line of code.
Can anyone help?
解决方案
empty
is an object method; you want to call it, not get its memory address. To make a function call, add trailing parenthesis to specify a parameter list to pass in to the call (in this case, a parameter list with no values in it), eg:
if (CurrentMap->empty()) {
推荐阅读
- python - 如何压缩小于 100mb 的 csv gzip?
- python - 无法使用 pandas 和 sqlalchemy 更改 VARCHAR 长度
- mysql - 如何按普通列计算实体数?
- python - 为什么我的正则表达式不能正确返回 group(0)?
- node.js - Sequelize destroy 无法测试真实性
- css - 如何使容器中的文本 A 包含在可以由文本 B 提升的容器宽度中?
- python - 如何在不使用迭代器和蛮力的情况下在python中查找列表中元素的所有两位数组合
- javascript - 在javascript中打印一个8位字节的二进制补码字符串
- javascript - 如何在 VueJS 中动态提供 API 发送的 pdf 文件?
- php - 保存 PHPSpreadSheet 对象