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!!!");----- ...
随机推荐
- vue项目中要实现展示markdown文件[转载]
转载 版权声明:本文为CSDN博主「齐天二圣」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明.原文链接:https://blog.csdn.net/nihaoa5 ...
- CheckList 如何梳理可减少上线的验证时间(总结篇)
对CheckList的执行发起的思考? (1)功能越来越多,CheckList越补充越多,执行CheckList时间越来越长,如何减少上线的验证时间?(2)减少上线验证的时间外,如何保证质量?上线后少 ...
- Django 会议室预定
表结构分析: from django.db import models # Create your models here. from django.db import models from dja ...
- C#中的Byte,String,Int,Hex之间的转换函数。
/// <summary> Convert a string of hex digits (ex: E4 CA B2) to a byte array. </summary> ...
- 在Tex live和Beamer环境下编译中文
在Tex live和Beamer环境下编译中文时,容易出现缺少$的提示错误.它有可能是由于特殊字符所致,如下划线: 也有可能是插图有误所致.
- C语言实现文件类型统计函数
#include<dirent.h> #include<limits.h> #include<sys/stat.h> #include<stdio.h> ...
- [golang][译]使用os/exec执行命令
[golang][译]使用os/exec执行命令 https://colobu.com/2017/06/19/advanced-command-execution-in-Go-with-os-exec ...
- CF1188B/E Count Pairs(数学)
数同余的个数显然是要把\(i,j\)分别放到\(\equiv\)的两边 $ (a_i + a_j)(a_i^2 + a_j^2) \equiv k \bmod p $ 左右两边乘上\((a_i-a_j ...
- C++概念分析之 重载、重写(覆盖)和隐藏的区别
一.基本概念区别: 重载:是指同一可访问区内被声明的几个具有不同参数列(参数的类型,个数,顺序不同)的同名函数,根据参数列表确定调用哪个函数,重载不关心函数返回类型. 隐藏:是指派生类的函数屏蔽了与其 ...
- mysql小白入门
mysql简介 1.什么是数据库 ? 数据库(Database)是按照数据结构来组织.存储和管理数据的仓库,它产生于距今六十多年前,随着信息技术和市场的发展,特别是二十世纪九十年代以后,数据管理不再仅 ...