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!!!");----- ...
随机推荐
- Easy sssp(spfa判负环与求最短路)
#include<bits/stdc++.h> using namespace std; int n,m,s; struct node{ int to,next,w; }e[]; bool ...
- MenuOS扩展(课堂时间作业)
MenuOS扩展实验 1.编译内核 2.制作根文件系统 rm menu -rf 强制删除原menu文件 git clone https://github.com/mengning/menu.git 从 ...
- [Usaco2006 Jan] Redundant Paths 分离的路径
1718: [Usaco2006 Jan] Redundant Paths 分离的路径 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1132 Solv ...
- LINQ查询表达式(3) - LINQ 查询分组
对查询结果进行分组 分组是 LINQ 最强大的功能之一. 下面的示例演示如何以各种方式对数据进行分组: 按照单个属性. 按照字符串属性的首字母. 按照计算出的数值范围. 按照布尔谓词或其他表达式. 按 ...
- 结构型模式(五) 外观模式(Facade)
一.动机(Motivate) 在软件系统开发的过程中,当组件的客户(即外部接口,或客户程序)和组件中各种复杂的子系统有了过多的耦合,随着外部客户程序和各子系统的演化,这种过多的耦合面临很多变化的挑战. ...
- 第三节.vue.js属性与方法
1. <!DOCTYPE html><html><head><meta charset="UTF-8"><title>I ...
- 2-使用git管理一个单片机程序
https://www.cnblogs.com/yangfengwu/p/10842205.html 我用电脑压缩一个文件,然后通过git上传,然后在新买的linux系统通过wget 网络下载这个压缩 ...
- [nginx]nginx的一个奇葩问题 500 Internal Server Error phpstudy2018 nginx虚拟主机配置 fastadmin常见问题处理
[nginx]nginx的一个奇葩问题 500 Internal Server Error 解决方案 nginx 一直报500 Internal Server Error 错误,配置是通过phpstu ...
- 无旋Treap模板
传送门 Code #include<bits/stdc++.h> #define ll long long #define max(a,b) ((a)>(b)?(a):(b)) # ...
- P5385 [Cnoi2019]须臾幻境(LCT+主席树,思维题)
题目 P5385 [Cnoi2019]须臾幻境 做法 考虑一条边\((u,v)\)是否\([L,R]\)中的贡献:\([L,R]\)中第一条位于\(u,v\)链的边,则减少了一个联通块 实现:\(LC ...