600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > no match for call to ‘(std::__cxx11::string {aka std::__cxx11::basic_string

no match for call to ‘(std::__cxx11::string {aka std::__cxx11::basic_string

时间:2024-04-11 06:27:20

相关推荐

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

参考答案:

/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 objectupon construction.

初始化是在已经构造成功的基础上进行的。

When yoursetName()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'sinitialization 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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。