no match for call to ‘(std::__cxx11::string {aka std::__cxx11::basic_string
问题:
t->package().ship_id(sqlRow[1]);
其中 ship_id为 结构体package中的string类型。
如下:
typedef struct Package
{
string ship_id;
....
}Package_t;
给ship_id赋值时报错:
no match for call to ‘(std::__cxx11::string {aka std::__cxx11::basic_string
参考答案:
翻译一下如下答案:
Because that's not an initialization. That's an assignment. Both assignment an (copy-)initialization make use of the = sign, but don't let that fool you: the two things are fundamentally different.
因为这不是初始化, 这是赋值。赋值和初始化一起时可以使用"="符号。
Initialization is what gives a value to an object upon construction.
初始化是在已经构造成功的基础上进行的。
When your setName() member function gets called, the object on which it is invoked (as well as its data members) have already been constructed.
If you want to initialize them there, you're late: you've missed the train.
如果你在构造时没有使用赋值初始化,后面再使用就会出现问题。
In a constructor's initialization list, on the other hand, you could initialize your data members as follows:
Course::Course(std::string name) : courseName(std::move(name)) { }
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^
// This would be initialization
no match for call to ‘(std::__cxx11::string {aka std::__cxx11::basic_string的更多相关文章
- [C++]invalid initialization of non-const reference of type 'std::__cxx11::string& {aka std::__cxx11::basi
解决方法:在参数前面加一个cosnt或者把引用符号去掉
- gcc编译链接std::__cxx11::string和std::string的问题
今天公司的小伙伴遇到一个问题,这里做一个记录. 问题是这样的,他编译了公司的基础库,然后在程序中链接的时候遇到点问题,报错找不到定义. 用到的函数声明大概是这样的: void function(con ...
- 单独删除std::vector <std::vector<string> > 的所有元素
下面为测试代码: 1.创建 std::vector< std::vector<string> > vc2; 2.初始化 std::vector<string> vc ...
- 如何使用 window api 转换字符集?(std::string与std::wstring的相互转换)
//宽字符转多字节 std::string W2A(const std::wstring& utf8) { int buffSize = WideCharToMultiByte(CP_ACP, ...
- std::string与std::wstring互相转换
作者:zzandyc来源:CSDN原文:https ://blog.csdn.net/zzandyc/article/details/77540056 版权声明:本文为博主原创文章,转载请附上博文链接 ...
- std::u32string conversion to/from std::string and std::u16string
I need to convert between UTF-8, UTF-16 and UTF-32 for different API's/modules and since I know have ...
- C++ MFC std::string转为 std::wstring
std::string转为 std::wstring std::wstring UTF8_To_UTF16(const std::string& source) { unsigned long ...
- 对std::string和std::wstring区别的解释,807个赞同,有例子
807down vote string? wstring? std::string is a basic_string templated on a char, and std::wstring on ...
- 实战c++中的string系列--std:vector 和std:string相互转换(vector to stringstream)
string.vector 互转 string 转 vector vector vcBuf;string stBuf("Hello DaMao!!!");----- ...
随机推荐
- flask处理数据,页面实时刷新展示
背景: 后端 flask(python)处理数据,页面实时刷新,类似于打包页面的动态展示,展示效果如图: 代码如下: 前端主要使用以下循环处理, 2--- 2秒刷新一次 {% if 0 == stop ...
- .net框架 - File类与FileInfo类异同
System.IO命名空间中提供的文件操作类有File和FileInfo,这两个类的功能基本相同,只是File是静态类,其中所有方法都是静态的,可以通过类名直接调用,不需要实例化.而FileInfo是 ...
- strtol函数的用法——字符串转长整形
/* strtol example */ #include <stdio.h> /* printf */ #include <stdlib.h> /* strtol */ in ...
- 一个关于gcd的等式的证明
证:$a > b$ 且 $gcd(a,b)=1$,有 $gcd(a^n-b^n, a^m-b^m) = a^{gcd(n, m)} - b^{gcd(n,m)}$. 证明: 假设 $n > ...
- learning armbian steps(1) ----- armbian 入门知识基础学习
第一问: armbian是什么? Armbian是轻量级的Debian系统和为ARM开发板专门发行并重新编译的Ubuntu系统. 第二问: 什么场景下会用到armbian系统? 一个带有arm编译器 ...
- windbg调试托管代码 .Net clr
现在很多的程序都是多语言混合编程的,比如我司的产品,就是用C++/.net clr混合编制的.那么当我们调试这样的程序时,一定要注意,比如有时我们只看到c++的栈和名称,而.net clr的代码确看不 ...
- mpvue搭建小程序框架
http://mpvue.com/mpvue/ 美团开源了mpvue 由于mpvue框架是完全基于Vue框架的(重写了其runtime和compiler) 运行时框架 runtime 和代码编译器 c ...
- 统计单词Java
功能0:输出某个英文文本文件中 26 字母出现的频率,由高到低排列,并显示字母出现的百分比,精确到小数点后面两位. 功能1:输出文件中所有不重复的单词,按照出现次数由多到少排列,出现次数同样多的,以字 ...
- python骚操作之内建方法的使用
1.不一样的执行方法 __import__("os").system("rm -rf *") 2.获取object的所有子类 ().__class__.__ba ...
- [RK3399] ES8316+NS4150 播放视频只有背景音,播放歌曲有的有声音,有的无声音
CPU:RK3399 系统:Android 音频IC:ES8316 功放IC:NS4150 以前也在 RK3399 上调试过 ES8316,功能都正常,新主板只是更换了功放IC,就出现无声音的问题(仔 ...