草庐IT

assignment-operator

全部标签

c++ - 使用 C++ "operator new"而不是 CoCreateinstance 来创建 COM 对象是否安全?

这可能是一个菜鸟COM问题,但谷歌搜索提出的问题多于提供答案:对本地COM实例使用“operatornew”而不是CoCreateInstance是否安全?我做了什么:我实现了IOperationsProgressDialog接口(interface)http://msdn.microsoft.com/en-us/library/windows/desktop/bb775368(v=vs.85).aspx通过使用公共(public)继承,从而也实现了IUnknown接口(interface)。我通过“newRecyclerProgressCallback”创建了一个实例,并将其放入CO

c++ - 在没有分配器的情况下在容器中遵守传播_on_copy_assignment 的习语

假设您有一个Container,它在内部使用其他标准容器来形成更复杂的数据结构。值得庆幸的是,标准容器已经被设计为完成所有必要的工作,以确保分配器被复制/分配等。所以,通常如果我们有一些容器c,并且在内部它有一个std::vector,我们可以写一个复制赋值运算符,它只是说:Container&operator=(constContainer&c){m_vec=c.m_vec;return*this;}事实上,我们甚至不必写它(因为它只是默认的复制赋值运算符所做的),但让我们说在这种情况下,默认运算符不会执行一些额外的必需逻辑:Container&operator=(constCont

c++ - operator[](const char *) 歧义

下面的代码#includestructFoo{operatordouble(){return1;}intoperator[](std::stringx){return1;}};intmain(){Foo()["abcd"];}使用g++编译良好,但使用clang和intel编译器编译失败,因为声明的方法和native运算符[]之间存在歧义。如果Foo隐式转换为int,我会很清楚,但这里转换为double。这不是解决了歧义吗? 最佳答案 §13.3.3.1.2[over.ics.user]/p1-2:Auser-definedconv

C++ [错误] 'operator==' 不匹配(操作数类型为 'Vehicle' 和 'const Vehicle')

我正在为我的学校做一个项目(我还是个初学者),我遇到了以下问题:"[Error]nomatchfor'operator=='(operandtypesare'Vehicle'and'constVehicle')"Vehicle是我项目中的一个类。这就是给我错误的原因:intDayLog::findWaitingPosistion(Vehicleconst&v){if(find(waitingList.begin(),waitingList.end(),v)!=waitingList.end())return1;}waitingList是Vehicle对象的vector。我搜索并找不到答

c++ - vector.assign() 按顺序赋值

下面的定义是否明确?std::vectorv{"test"};v.assign(1,v.at(0));如果在构建新序列之前旧序列被销毁传递给assign的引用将失效,因此程序将是病式的。标准是否提到这种情况(值(value)是旧序列的一部分)或任何地方类似的东西,使这个结构合式?我找不到任何东西。来自Dinkumware的标准库实现拷贝使用VS2010(_Assign_n是由assign内部调用的):void_Assign_n(size_type_Count,const_Ty&_Val){//assign_Count*_Val_Ty_Tmp=_Val;//incase_Valisins

C++ Operator () 括号重载

我最近问了一个关于从vector中删除项目的问题。好吧,我得到的解决方案有效,但我不明白它-我找不到任何解释它的文档。structRemoveBlockedHost{RemoveBlockedHost(conststd::string&s):blockedHost(s){}//righthere,Icanfindnodocumentationonoverloadingthe()operatorbooloperator()(HostEntry&entry){returnentry.getHost()==blockedHost||entry.getHost()=="www."+blocke

c++ - 为什么重载 operator<< 来打印 Eigen 类成员会导致段错误?

对于下面的结构structTestClass{TestClass():mat(Eigen::Matrix3i::Zero()){}Eigen::Matrix3imat;};我想要一个重载的operator打印mat加入std::cout.我试过了std::ostream&operator这会导致段错误。谁能给我解释一下为什么?一个最小的工作示例:#include#includestructTestClass{TestClass():mat(Eigen::Matrix3i::Zero()){}Eigen::Matrix3imat;};std::ostream&operator我在Ubun

windows - 关于进程地址空间中的 NULL-Pointer Assignment Partition 的问题

我正在阅读,下面是一些引述:Eachprocess'virtualaddressspaceissplitintopartitions.Onx8632-BitWindows,thepartitionof0x00000000-0x0000FFFF(inclusive)iscalledNULL-PointerAssignmentPartition.ThispartitionissetasidetohelpprogrammerscatchNULL-pointerassignments.Ifathreadinyouraprocessattemptstoreadfromorwritetoamemo

windows - 适用于 Windows 的 Docker : cannot assign requested address

如何在Hyper-V上设置运行Docker1.12的多主机?我可以轻松分配一个127.x.x.xip,但我想分配例如10.240.0.x.这是我的docker-compose.yaml:version:'2'services:nginx:image:nginx:lastestports:-"127.0.0.100:80:80"如果我尝试分配10.240.0.100,我会收到此错误:启动userland代理时出错:listentcp10.240.0.100:80:bind:cannotassignrequestedaddress我错过了什么?我是否必须配置Windows以支持这些地址?

python - 什么 "command verbs"可用于 os.startfile 'operation' 参数,它们有什么作用?

根据Pythondocumentation,os.startfile有两个参数:path和operation。路径描述得相当好并且不言自明,但是对于操作,只需要说明:Whenanotheroperation[(not'open')]isgiven,itmustbea“commandverb”thatspecifieswhatshouldbedonewiththefile.CommonverbsdocumentedbyMicrosoftare'print'and'edit'(tobeusedonfiles)aswellas'explore'and'find'(tobeusedondire