问题:
 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. [Exception] java.util.MissingFormatArgumentException

    java.util.MissingFormatArgumentException: Format specifier 's' at java.util.Formatter.format(Formatt ...

  2. 任何人都适合的常用Chrome插件(工欲善其事必先利其器)

    1.划词翻译 介绍链接:http://t.cn/RqpoGU4 下载地址: Chrome 应用商店(请翻墙). 下载 .crx 安装包手动安装 功能如下: - 支持几乎所有语言的翻译与阅读,并且同时支 ...

  3. ldap系列-基础知识

    来源:关键字排名 ldap 是什么? LDAP(Lightweight Directory Access Protocol)即轻量级目录访问协议,提供信息服务.那啥是目录服务呢? 目录服务是一种特殊的 ...

  4. Djiango权限组件

    一. login中注册 权限url def login(request): if request.method == "POST": username = request.POST ...

  5. 2019-2020-1 20199302《Linux内核原理与分析》第六周作业

    一 .万能函数 1.过程抽象 (1)接口:指明模块要做什么,标识符/类型.函数等,.h ,函数调用者 (2)实现:指明模块如何完成接口,一个接口多个实现(可能),.c ,函数实现者 (3)函数签名:函 ...

  6. IDEA设置提示生成序列化ID

    背景: 实现Serializable接口的类,没有提示生成序列化ID 解决问题: 1.FIle->Settings->Editor->inspections 2.点击java-> ...

  7. mysql5.7的手动安装

    1.安装必要的组件    | yum install –y autoconf automake imake libxml2-devel expat-devel cmake gcc gcc-c++ li ...

  8. asp.net log4net

    引用Log4net.dll Global.asax.cs的Application_Start过程中添加如下代码 log4net.Config.DOMConfigurator.Configure(); ...

  9. js检测手机上是否有此APP,有的话打开应用,没有的话跳转到appstore

    //html代码中 的 a 标签,以微信为例,默认的是调用weixin scheme,去打开本机的微信,如果没有则跳转到相应连接 <a href="weixin://" cl ...

  10. Mitmproxy的mimdump mimproxy mitmweb命令行性能对比

    引用官方的原话如下 Very cool test - thanks for sharing!