首先,当执行(12)时,std :: vector尝试分配一个 struct A的数组。不幸的是,struct A没有默认构造函数。所以,它不能构造数组中的每个元素。 其次,std :: vector将尝试将A(2)分配给其中一个元素。 新分配的数组中的可用条目。不幸的是,你确实没有提供赋值运算符,所以默认值就是。 此外不幸的是,默认的赋值运算符试图复制 const成员u,你不能改变const成员。这是您在下面看到的 错误消息。You have a number of problems with this code.First, when (12) is executed, std::vector tries to allocate an array ofstruct A. Unfortunately, struct A has no default constructor. So, itcannot construct each element in the array.Second, std::vector will then try to assign A(2) to one of theavailable entry in the newly allocated array. Unfortunately, you didnot provide an assignment operator, so the default one kicks in.Furthermore unfortunate, the default assignment operator tries to copythe const member u, and you cannot change const members. This is theerror message you are seeing below. - -kira---kira 这篇关于const类成员的赋值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-28 19:26
查看更多