- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
在下面的代码片段 1 中,mKnownSRList 定义如下:
std::vector<EndPointAddr*> mKnownSRList;
我收到代码片段 2 中显示的编译错误。你能告诉我这段代码有什么问题吗? getTipcAddress() 和 compareTo 函数的内容显示在下面的代码片段 3 和 4 中。
CODE SNIPPET 1(标出编译错误)
void
ServiceRegistrarAPI::removeKnownSR(EndPointAddr & srEndPointAddr)
{
auto last =
std::remove_if(mKnownSRList.begin(),
mKnownSRList.end(),
[srEndPointAddr]( EndPointAddr* o )
{
//LINE 355 is the following
EndPointTipcAddr myTipcAddress = srEndPointAddr.getTipcAddress();
EndPointTipcAddr otherTipcAddress = o->getTipcAddress();
return (myTipcAddress.compareTo(otherTipcAddress));
});
if(*last != nullptr)
{
delete *last;
}
mKnownSRList.erase(last, mKnownSRList.end());
}
SNIPPET 2(编译错误)
ServiceRegistrarAPI.cpp:355:72: error: passing ‘const EndPointAddr’ as ‘this’ argument of ‘EndPointTipcAddr& EndPointAddr::getTipcAddress()’ discards qualifiers [- fpermissive]
代码片段 3(getTipcAddress 函数)
EndPointTipcAddr & getTipcAddress() { return mTipcAddress; }
CODE NIPPET 4(compareTo 函数)
bool
EndPointTipcAddr::compareTo(EndPointTipcAddr &rhs)
{
if( (mType == rhs.getType()) && (mInstanceNo == rhs.getInstanceNo()) )
{
return true;
}
return false;
}
最佳答案
参见 S5.1.2.5:
The closure type for a lambda-expression has a public inline function call operator (13.5.4) whose parameters and return type are described by the lambda-expression’s parameter-declaration-clause and trailingreturn- type respectively. This function call operator is declared const (9.3.1) if and only if the lambdaexpression’s parameter-declaration-clause is not followed by mutable. It is neither virtual nor declared volatile. Default arguments (8.3.6) shall not be specified in the parameter-declaration-clause of a lambdadeclarator. Any exception-specification specified on a lambda-expression applies to the corresponding function call operator. An attribute-specifier-seq in a lambda-declarator appertains to the type of the corresponding function call operator. [ Note: Names referenced in the lambda-declarator are looked up in the context in which the lambda-expression appears. —end note ]
基本上,这意味着生成的仿函数的 operator() 默认是 const
,并且您已经按值捕获,并且这个捕获的变量是生成的仿函数的成员。
所以,您有两个选择:
将您的 lambda 更改为以下内容(注意参数声明子句后面的 mutable
):
[srEndPointAddr](EndPointAddr* o) 可变 { ... }
关于c++ - const XX 丢弃限定符 [- fpermissive],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15618415/
我一直在使用 OpenGL 编写程序。最近,我开始学习OpenGL着色语言。我是新手;因此,请在回答中详细说明。 我的问题是: GLSL 中有哪些不同类型的变量(限定符)? 它们的用途是什么? 它们有
这个问题在这里已经有了答案: typedef pointer const weirdness (6 个答案) 关闭 8 年前。 我有一个结构体 type_s。然后我将指向 struct type_s
我有一个 Point2D 类如下: class Point2D{ int x; int y; public: Point2D(int inX,
当应用于指向指针的指针等时,我在推断什么是 const 时遇到了一些麻烦。即,什么是 const 当你有 const Foo **foo; 我可以在这里更改 **foo 中的内容吗?如 foo[0]
限定符 有时候不知道要匹配多少字符。为了能适应这种不确定性,正则表达式支持限定符的概念。这些限定符可以指定正则表达式的一个给定组件必须要出现多少次才能满足匹配。 下表给出了各种限定符及其含义的说
我有一个包含字符名称的数组结构。我想使用 qsort 按字母顺序对它们进行排序,但是我一直收到一条错误消息,说“初始化丢弃了指针目标类型中的‘const’限定符”。我相信我的 cmpmi() 函数和
我是 Java EE/JSF 的新手,现在阅读 CDI 限定符 - 更改类实现的可能性。这很好,但我有一个问题。据我了解,我可以使用限定符更改类实现,但我需要在使用此实现的任何地方更改它。在一个地方进
假设我有以下目录结构: $ mkdir -p a/1 $ ln -s a b 查找目录,我也得到了符号链接(symbolic link)中的目录: $ print -l */*(/) a/1 b/1
我正在尝试创建一个 const 结构数组,但我不断得到 error initializer element is not a compile time constant 我使用的是keil IDE。这
#include using namespace std; class Point { private: int x, y; // Private data members public:
我想使一个方法有条件地成为常量。也就是说,我们有 template class A { // stuff }; 根据模板参数的值,要么 void method() const; 或 void
由于 const int 特化导致以下错误: #include using std::cout; using std::endl; template void g(T val) { cou
同时适用于移动设备和平板电脑的 Titanium 项目,完美地完成了移动版本,但在平板设计时面临一些复杂性。 下面是 Titanium 支持的限定符矩阵,但我找不到任何针对 Android-Table
我正在研究 C++ 和 gtkmm,试图创建一个自定义类,它调用 .glade 文件来构建一个 Gtk 而不是基本的界面。此类派生自 Gtk::Window,但是当我调用类本身的 get_widget
我编写了以下代码来测试 const 成员函数:当我有数据成员的 const 限定符时,它编译并运行良好char *data 和构造函数的参数。但是,如果我从中删除 const数据成员和构造函数,我得到
您好,我正在使用 C++ 内置算法。我这里有这段代码: #include #include #include using namespace std; bool isDon(string& na
我的问题与 Time 项目有关,我将在下面完整发布该项目以提供背景信息。我所做的大部分都是正确的,但是当涉及到加法和减法运算符定义时,我遇到了范围界定错误的问题。编译器找不到我的私有(private)
我有以下代码- int acb(const uint16 *MsgPtr) { uint16 *p = (MsgPtr + 1); printf("%d", *p); } 我收到以下警告 - 在为 p
我在结构中有一个指向结构实例链表的指针字段。 struct myStruct { some fields... struct list_objects * volatile list;
所以我在维基百科的一篇文章(粗略翻译)中遇到了以下定义: Modifier (programming) - element of source code being a phrase of given
我是一名优秀的程序员,十分优秀!