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!!!");----- ...
随机推荐
- python_并发编程——队列
1.队列 from multiprocessing import Queue q = Queue(5) #创建队列对象,队列大小为5,队列中只能存放5个元素 q.put(1) #往队列中添加元素 q. ...
- GITHUB下载源码
从昨天开始就想着从GitHub上下载一个开源的Vue的实战项目,希望能从中学习更多的Vue的实用内容,结果搞了半天好不容易下载了,不知道怎么弄.然而,今天终于成功了,激动地我赶紧来记录一下. 如何从G ...
- 09 webpack的介绍
webpack干嘛的?: 模块打包机,分析目录结构,找到js模块(包括浏览器不能直接识别的代码 typscript sass...),打包成合适的格式供浏览器访问 webpack是一款模块加载器兼打 ...
- go函数类型的使用
Go函数类型的使用 type myfunc func() string // 声明函数变量 func main() { fn := func() string { return "bbb&q ...
- python列表命令
创建普通列表:member;: 创建混合列表:mix: 创建空列表:empty >>> member = ['lala','oo'] >>> member ['la ...
- (尚003).Vue_模板语法
1.双大括号表达式 2.指令一:强制数据绑定 3.指令二;绑定事件监听 test003.html<!DOCTYPE html><html lang="en"> ...
- 自用java购物
@RequestMapping("listgoodscart") public ResultEntity listGoodsCart(@RequestParam(name = &q ...
- learning java AWT 绝对定位
import javax.swing.*; import java.awt.*; public class NullLayoutTest { Frame f = new Frame("测试窗 ...
- 通过django-crontab扩展来实现 定时任务
pip install django-crontab 基本格式 : * * * * * 分 时 日 月 周 命令 M: 分钟(0-59).每分钟用*或者 */1表示 H:小时(0-23).(0表示0点 ...
- 38、数据源Parquet之使用编程方式加载数据
一.概述 Parquet是面向分析型业务的列式存储格式,由Twitter和Cloudera合作开发,2015年5月从Apache的孵化器里毕业成为Apache顶级项目,最新的版本是1.8.0. 列式存 ...