草庐IT

copy-initialization

全部标签

C++11 统一初始化 : Field initializer is not constant

我正在尝试像这样实例化一组字符串:classPOI{public:...staticconststd::setTYPES{"restaurant","education","financial","health","culture","other"};...}现在,当我这样做时,我得到了这些错误(全部在这一行):error:fieldinitializerisnotconstantstaticconststd::setTYPES{"restaurant","education","financial","health","culture","other"};error:in-class

c++ - 为什么这里调用的是 Copy Constructor 而不是普通的 Constructor 和重载的赋值运算符?

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:IsthereadifferenceinC++betweencopyinitializationanddirectinitialization?CopyconstructorsandAssignmentOperators我有一个C类,我在其中重载了Normal、复制构造函数和赋值运算符以打印被调用内容的踪迹。我写了以下代码来测试什么时候被调用?Cc1;-->NormalConstuctor..//understoodFineCc2;c2=c1;-->Normalconstructor+assignmentop

c++ - copy-and-swap 技术在赋值运算符函数中使用复制构造函数

我正在阅读“EffectiveC++byScottMeyers”,其中第11项建议在我的赋值运算符中使用“copy-and-swap”技术:Widget&Widget::operator=(constWidget&rhs){Widgettemp(rhs);//Copyconstructorswap(temp);//Swapwith*thisreturn*this;}但是在Item12中是这样写的:Itmakesnosensetohavecopyassignmentoperatorcallthecopyconstructor.我认为第11项和第12项是矛盾的。我理解错了吗?

c++ - 为什么 clang++ 报告与 "value stored to ' .. .' during its initialization is never read"的结构化绑定(bind)?

我有以下测试用例:testcase("[room]exits"){auto[center,east,north,south,west]=make_test_rooms();check_eq(center->east(),east);check_eq(center->north(),north);check_eq(center->south(),south);check_eq(center->west(),west+1);}当我编译它时,clang++(clangversion5.0.1(tags/RELEASE_501/final))报告:room.cpp:52:7:note:Valu

当使用node_modules/.bin/webpack时,无法读取未定义的属性(mix.initialize())

我正在尝试编译node_modules/.bin/webpack我得到了这个错误:Mix.initialize();^TypeError:Cannotreadproperty'initialize'ofundefinedatObject.(/home/vagrant/Code/stream/webpack.config.js:9:4)atModule._compile(module.js:570:32)atObject.Module._extensions..js(module.js:579:10)atModule.load(module.js:487:32)attryModuleLoad(m

c++ - 为什么嵌套的initializer_list会导致内存泄漏

最近我将我的项目升级到VisualStudio2013。因此现在可以使用initializer_list功能。我需要在我的单元测试中初始化测试数据。但是我在使用嵌套的initialize_lists时遇到了内存泄漏。#include#includestructTest_Fixture{Test_Fixture():test_data({std::make_shared>(std::vector{0,1}),std::make_shared>(std::vector{2,3,4})}){}std::vector>>test_data;};BOOST_FIXTURE_TEST_CASE(t

c# - 无法在我的 WPF 应用程序中使用 Array.Copy()

我是一名C++开发人员,最近开始从事WPF方面的工作。好吧,我在我的应用程序中使用Array.Copy(),看起来我无法完全获得所需的结果。我在我的C++应用程序中做了如下操作:staticconstsignedcharversion[40]={'A','U','D','I','E','N','C','E',//name0,0,0,0,0,0,0,0,//reserved,firmwaresize0,0,0,0,0,0,0,0,//boardnumber0,0,0,0,0,0,0,0,//variant,version,serial0,0,0,0,0,0,0,0//datecode,r

c++ - 空 initializer_list 上的赋值运算符

您能解释一下STL容器如何处理初始化列表为空的赋值运算符吗?当我做这样的事情时:vectorv;v={};调用的函数不是:vector&operator=(initializer_listil);但是:vector&operator=(vector&&x);另一方面,当我对自己的类(class)做类似的事情时:structA{A&operator=(constA&){return*this;}A&operator=(A&&){return*this;}A&operator=(initializer_list){return*this;}};/*...*/Aa;a={};代码无法在VS2

python - Py_Initialize 运行需要哪些文件?

我正在编写一段从C/C++应用程序运行Python函数的简单代码。为了做到这一点,我设置了PYTHONPATH并按如下方式运行初始化:Py_SetPythonHome("../Python27");Py_InitializeEx(0);然后我导入我的模块并运行我的函数。它工作得很好。我现在正在尝试为我的同事构建一个安装程序来运行我的代码。出于显而易见的原因,我想尽量减少需要包含在此安装程序中的文件数量。谷歌搜索这个主题告诉我,我应该能够包含文件“Python27.lib”和“Python27.dll”,然后压缩“DLL”和“Lib”文件夹并包含它们。但是,当我尝试这样做时,Py_Ini

c++ - 为 ARM mbed 编译 PicoTCP 时未定义对 pico_dhcp_server_initiate 的引用

我正在从事一个必须使用PicoTCP的项目(请参阅https://developer.mbed.org/users/daniele/code/PicoTCP/,我使用的是该库的旧版本)。在我的main.cpp文件中,我有以下代码:#include"pico_stack.h"#include"pico_dhcp_server.h"intmain(void){//createDHCPserverstructpico_dhcpd_settingss={};s.my_ip.addr=long_be(0x0a280001);/*10.40.0.1*/pico_dhcp_server_initia