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

no match for call to ‘(std::__cxx11::string {aka std::__cxx11::basic_string的更多相关文章

  1. [C++]invalid initialization of non-const reference of type 'std::__cxx11::string& {aka std::__cxx11::basi

    解决方法:在参数前面加一个cosnt或者把引用符号去掉

  2. gcc编译链接std::__cxx11::string和std::string的问题

    今天公司的小伙伴遇到一个问题,这里做一个记录. 问题是这样的,他编译了公司的基础库,然后在程序中链接的时候遇到点问题,报错找不到定义. 用到的函数声明大概是这样的: void function(con ...

  3. 单独删除std::vector <std::vector<string> > 的所有元素

    下面为测试代码: 1.创建 std::vector< std::vector<string> > vc2; 2.初始化 std::vector<string> vc ...

  4. 如何使用 window api 转换字符集?(std::string与std::wstring的相互转换)

    //宽字符转多字节 std::string W2A(const std::wstring& utf8) { int buffSize = WideCharToMultiByte(CP_ACP, ...

  5. std::string与std::wstring互相转换

    作者:zzandyc来源:CSDN原文:https ://blog.csdn.net/zzandyc/article/details/77540056 版权声明:本文为博主原创文章,转载请附上博文链接 ...

  6. 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 ...

  7. C++ MFC std::string转为 std::wstring

    std::string转为 std::wstring std::wstring UTF8_To_UTF16(const std::string& source) { unsigned long ...

  8. 对std::string和std::wstring区别的解释,807个赞同,有例子

    807down vote string? wstring? std::string is a basic_string templated on a char, and std::wstring on ...

  9. 实战c++中的string系列--std:vector 和std:string相互转换(vector to stringstream)

    string.vector 互转 string 转 vector vector  vcBuf;string        stBuf("Hello DaMao!!!");----- ...

随机推荐

  1. js数组的操作大全

    用 js有很久了,但都没有深究过js的数组形式.偶尔用用也就是简单的string.split(char).这段时间做的一个项目,用到数组的地方很多,自以为js高手的自己居然无从下手,一下狠心,我学!呵 ...

  2. Django自定义filter

  3. python - django (路由)

    # """ # Django路由分配系统简介: Django project目录中的urls.py文件中, 以Python [ ( ) ]的数据类型记录了可以访问到该站点 ...

  4. Java使用IE浏览器下载文件,文件名乱码问题

    String userAgent = request.getHeader("user-agent").toLowerCase(); if (userAgent.contains(& ...

  5. codecs 1264 芳香数

    1264 芳香数 题目描述 Description This question involves calculating the value of aromatic numbers which are ...

  6. (32)Vue模板语法

    模板语法 文本: <span>Message: {{ msg }}</span> v-once 一次性地插值,当数据改变时,插值处的内容不会更新 <span v-once ...

  7. Python3文件

    open()方法 Python open()方法永于打开一个文件,并返回文件对象,并对文件进行处理过程中都需要用到这个方法,如果该文件无法被打开,则抛出OSError 注意:使用open()方法一定要 ...

  8. UDP 区别于 TCP 的特点

    TCP 我们了解得多了,所以今天我们站在 UDP 的角度,探讨一下 UDP 区别于 TCP 的特点. 1. 面向无连接 UDP 比 TCP 简单得多,不需要“三次握手”来建立连接,直接把内容发送出去. ...

  9. [FUZZ]文件上传fuzz字典生成脚本—使用方法

    文件上传fuzz字典生成脚本-使用方法 原作者:c0ny1 项目地址:https://github.com/c0ny1/upload-fuzz-dic-builder 项目预览效果图: 帮助手册: 脚 ...

  10. jquery选择器(1)

    jQuery 元素选择器 jQuery 使用 CSS 选择器来选取 HTML 元素. $("p") 选取 <p> 元素. $("p.intro") ...