如何在结构体中传递指向CURL的指针到向量
How to pass pointer to CURL in struct to vector?
CURL * myHandle;
(... some operations)
std::vector<curl_a> * crl = &program_data::getInstance().curl_acc[80];
crl->push_back({ myHandle,true }); //look at bottom
push_back的struct似乎:
struct curl_a {
curl_a(){};
curl_a(CURL * d, int &l) :data(d), logged(l){};
CURL * data;
bool logged;
};
//header.h(单例模式)
std::unordered_map <int, std::vector<curl_a>> curl_acc;
现在告诉我,为什么push_back不起作用?编译器从struct .h返回错误
curl_a' : illegal member initialization: 'data' is not a base or member
问题似乎是您正在使用无效的第二个参数调用curl_a
构造函数。当参数明确需要一个l值(引用)时,您正在传递true
。
初始化时不使用值true
,而是使用整型变量。
int x = 1;
crl->push_back({ myHandle, x });
这是你的例子,但简化使用int*
而不是CURL*
: http://ideone.com/SzxESi
下面是一个使用true
作为参数的失败尝试的例子:http://ideone.com/HQtAaU
相关文章:
- 1d 智能指针不适用于语法 (*)++
- 在C#中处理C++指针而不使用unsafe的最佳方法
- 为什么使用 "this" 指针调用派生成员函数?
- 函数向量_指针有不同的原型,我可以构建一个吗
- 使用指针从C++中的数组中获取最大值
- 助记符和指向成员语法的指针
- 嵌入方指针压缩已禁用
- 数组的指针从不分段故障
- C++ 指针的内存地址和指向数组的内存地址如何相同?
- 何时在引用或唯一指针上使用移动语义
- 在C++中使用cURL和多线程
- QMetaObject invokeMethod的基于函数指针的语法
- 如何从 std::atomic 中提取指针 T<T>?
- 如何在 C# 中映射双 C 结构指针?
- C++将浮点指针值舍入为小数位数
- 为什么++(*p)更改指针值
- 调整大小后指向元素值的指针unordered_map有效?
- 正在将指针转换为范围
- 如何在结构体中传递指向CURL的指针到向量
- Curl_easy_cleanup不清除curl指针