问题:
 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

参考答案:

https://stackoverflow.com/questions/17262984/c-error-no-match-for-call-to-stdstring-aka-stdbasic-stringchar-st

翻译一下如下答案:

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

转载于:https://www.cnblogs.com/rohens-hbg/p/11303349.html

no match for call to ‘(std::__cxx11::string {aka std::__cxx11::basic_string相关推荐

  1. 【已解决】[Error] cannot pass objects of non-trivially-copyable type ‘std::string {aka class std::basic_s

    [Error] cannot pass objects of non-trivially-copyable type 'std::string {aka class std::basic_string ...

  2. linux wstring,关于linux环境下std::string转std::wstring的问题

    各位大家好,现在本人需要将string转为wstring,其中字符串有字母和中文(如:"/usr/工具") 本人在网上找了一下好多人多说一些代码能够转换: [code=c#incl ...

  3. 使用std实现string的TrimLeft与TrimRight功能

    使用过MFC的人都知道,MFC的字符串CString有些函数比较好用的,如: TrimLeft(), TrimRight()为CString所包含有的子函数,可以去掉左右空格符,但std::strin ...

  4. std::tr1::function and std::tr1::bind

    std::tr1::function and std::tr1::bind 每日一话 一本正经的胡说八道 引言 在C++的TR1中(Technology Report)中包含一个function模板类 ...

  5. C++ 20 std::chrono 库使用 | std::chrono::year_month_day |std::chrono::hh_mm_ss 使用

    最近在写异步日志库,结果为了偷懒完全用 C++20 的功能发现 C++20 的 g++11 的 timezone 支持还没有做完,根据 cppreference 的统计 g++ 只是 partial ...

  6. 解析 static auto x = []() { std::ios::sync_with_stdio(false);std::cin.tie(nullptr);return 0;}()

    前言 这两天在LeetCode上刷题的时候看见有好几个速度排名第一的代码中都有一段类似的代码,如下: static const auto io_sync_off = []() {// turn off ...

  7. 关于make提示must been abled with the -std=c++11 or -std=gnu++11 compiler options

    转:https://blog.csdn.net/zheng_weichao/article/details/78298928 在make后,出现错误,提示如下: /usr/include/c++/4. ...

  8. C++编译出现binding ‘const string {aka const std::__cxx11::basic_string<char>}’ to reference of type ‘std

    编译异常如下: 解决办法: 我的函数是这样的 string &larger(const string &s1, const string &s2){return s1.size ...

  9. 几种C++ std::string和std::wstring相互转换的转换方法

    第一种方法:调用WideCharToMultiByte()和MultiByteToWideChar(),代码如下(关于详细的解释,可以参考<windows核心编程>): #include ...

最新文章

  1. 一文了解卷积神经网络在股票中应用
  2. linux c execve, execlp, execvp, execle 执行文件 执行二进制 介绍
  3. php rpc连接Python,PHP语言之Python、PHP通过xml-rpc进行通信,xml-rpc中文的解决
  4. 【深度学习】——如何处理输入图像大小不一样的情况
  5. 认证服务器协议,基于口令的客户端/服务器认证协议
  6. java学习(90):Character方法大小写转换
  7. (137)FPGA面试题-Verilog HDL中function和task的区别(一)
  8. MySQL 到底能不能放到 Docker 里跑?
  9. Tensorflow——Variable变量(打印数字小实例)
  10. rabbitmq官方文档
  11. Xcode 模拟器Simulator手动下载(iOS 8 - iOS 12)
  12. python笔记:太困了,读取并显示按行业分类的股票数据提提神
  13. Docker目录映射
  14. 关于计算机安全的英语文章,计算机专业英语期末论文
  15. TestCenter测试管理工具问题详解(5)
  16. jQuery菜鸟教程01
  17. 充电桩检测设备TK4860E交流充电桩检定装置
  18. 相关系数(用来衡量两变量间相关关系的大小)
  19. 网络安全必备的五款免费网络漏洞扫描器
  20. Linux:解压bz2文件

热门文章

  1. 【树莓派】为树莓派配置或扩展swap分区
  2. 用ORBSLAM2运行TUM Dataset数据集Monocular Examples
  3. c#3.0加入的一些新特性——泛型集合
  4. Liux技巧总结之--解压各种文件
  5. 中文乱码,也许这个小技巧可以帮到你
  6. js生日计算年龄_用T-SQL计算明细年龄问题.
  7. ifconfig没有命令 kali_新装的Linux系统没有ifconfig命令?教你一键找回
  8. unity android模糊ios清晰,Unity NGUI UI 在iOS端的锯齿、模糊、颗粒感问题
  9. 冯诺依曼计算机程序及其执行,第4章冯.诺依曼计算机:机器级程序与其执行练习题答案解析...
  10. mysql 表分区 django_MySQL partition分区I