错误 C2165:'left-side modifier':无法修改指向数据的指针
error C2165: 'left-side modifier' : cannot modify pointers to data
我在尝试这段代码
演示.hpp
#ifndef DEMO_HPP
#define DEMO_HPP
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <vector>
using namespace std;
typedef boost::function<void(vector<int>)>func;
typedef void (_stdcall *Callback);
class funcPointer
{
public:
void add_call(int, func);
void call_back(int, Callback);
void push_elements();
vector<int> vec;
};
#endif
演示.cpp
#include <iostream>
#include "demo.hpp"
void funcPointer::add_call(int number, func f)
{
cout<<"number: "<<number << endl;
f(vec);
}
void funcPointer::push_elements()
{
vec.push_back(11);
vec.push_back(12);
vec.push_back(13);
}
void funcPointer::call_back(int x, Callback call)
{
cout << "x: " << x <<endl;
}
主.cpp
#include <iostream>
#include "demo.hpp"
void display(vector<int> v)
{
vector<int> ::iterator it;
for(it = v.begin(); it != v.end(); it++)
{
cout<< *it <<endl;
}
}
void Inside_callback()
{
cout << "Hello World" << endl;
}
int main()
{
funcPointer *fun = new funcPointer;
fun->push_elements();
fun->add_call(24, boost::bind(display, _1));
fun->call_back(10, &Inside_callback);
return 0;
}
编译时出现以下错误:
e:vs_c++boost_func_ptrboost_func_ptrdemo.hpp(12): error C2165: 'left-side modifier' : cannot modify pointers to data
我无法理解这个错误是什么,以及如何摆脱它。有人可以帮助我摆脱这个错误吗?
您必须通过以下方式定义回调的类型:
typedef void (_stdcall *Callback)();
您还应该按以下方式修改Inside_callback声明,以便编译代码:
void _stdcall Inside_callback()
相关文章:
- QT QOpenGLWidget:如何在不使用数据块复制的情况下修改VBO中的单个顶点值?
- 在 C++ 中修改 Grpc 双向流式处理期间的元数据
- 修改链表主函数代码,用户将在其中输入节点的索引和数据以及正确的消息
- C++:成员不可访问-使用友元函数允许一个类修改另一个类的成员数据
- 修改数据是否由 const shared_ptr&Ok 传递?
- 当原始数据是常量时,修改指针指向的位置是 UB 吗?
- 在不编写显式 setter 的情况下修改私有类数据成员的便捷方法是什么?模板有用吗?
- Windivert-修改数据包数据/有效载荷内容
- 修改跨 fork() 的指针中的数据
- 将数据添加到现有类,而无需继承、映射或修改类
- (C++)如何修改/使用数据结构,以便我们可以一次又一次地使用它们?
- Qt:如何使用sqlite数据库修改2个表中的数据记录
- 如何通过将JSON数据修改为RapidJson通过将其修改为其他模式
- 如何仅通过类方法修改类公共数据成员
- DPDK:修改捕获的数据包标头的最有效方法
- 是否要确保一个线程修改的任何数据类型的共享变量对其他线程可见
- 保护外部数据文件免受未经授权的修改
- 通知线程是否始终需要在修改期间锁定共享数据
- 排序向量不断修改数据并打印不正确的结果
- 高效查找应用了数据修改堆栈的缓冲区