草庐IT

copy-protection

全部标签

c++ - MI 和隐式复制构造函数错误(原为 : Under what conditions can a template be the copy constructor?)

我很确定这个问题的答案是,“模板永远不可能成为复制构造函数。”不幸的是,我只花了3个小时弄清楚为什么我会收到有关递归的警告,跟踪它到复制构造函数,看着调试器发疯,不让我看递归代码,最后跟踪到一个基础构造函数中缺少“&”。你看,我有一个复杂的基于策略的设计主机,它已经运行了一段时间了。我着手将两个策略合二为一并遇到了一个递归复制构造函数。将其缩小为一个策略,该策略需要提供一个构造函数,该构造函数可以采用一种XXX概念作为其参数,但在这种情况下,我只是放弃它。所以我写了structmy_policy{templatemy_polity(Tconst){}//missing'&'...oop

c++ - protected 成员在派生类中不可访问

为什么基类中的protected成员在派生类中无法访问?classClassA{public:intpublicmemberA;protected:intprotectedmemberA;private:intprivatememberA;ClassA();};classClassB:publicClassA{};intmain(){ClassBb;b.protectedmemberA;//thissaysitisnotaccesible,violation?//.....} 最佳答案 您可以访问protectedmemberAin

c++ - QFile::copy create 会创建文件的拷贝或将内容从一个文件移动到另一个文件吗?

我正在尝试使用C++/Qt将文件从一个位置复制到另一个位置(在设备中)我试过QFile::copy("path1/file","path2");我想将路径1中的文件复制到路径2中。path2没有该文件。我只是想知道这是否是正确的方法,因为上面的代码似乎不起作用。另外,我应该在尝试复制之前打开一个文件吗?需要帮助! 最佳答案 如果你想将path1/file复制到具有相同文件名的path2中,你需要这样做:QFile::copy("path1/file","path2/file");复制允许您更改文件的名称。示例:QFile::copy

c++ - std::copy 用于动态分配的指针

这可能是一个非常新手的问题。我正在处理的类(我们称之为MyClass)包含以下变量intnbins;double*bins;//=newdouble[nbins+i]因为我正在实现一个复制构造函数MyClass(constMyClass&source)我需要复制source.bins。我打算使用algorithm中的std::copy,但我发现的所有示例都展示了如何复制静态数组,如doublebins[]=。..或标准数据结构,如std::vector。我找不到任何示例,其中std::copy用于像double*bins=newdouble[nbins+i]这样的指针。所以,我的问题是

C++ move 语义 : why copy assignment operator=(&) is called instead of move assignment operator=(&&)?

我有以下代码:#include#includeusingstd::cout;structSomeType{SomeType(){}SomeType(constSomeType&&other){cout我希望move构造函数调用move赋值运算符。下面是这个程序的输出:SomeType(SomeType&&)operator=(constSomeType&)operator=(SomeType&&)如您所见,move赋值运算符已成功调用,但在move构造函数内分配给*this时未成功调用。为什么会发生这种情况,我能以某种方式解决它吗? 最佳答案

c++ - 当值为指针时尝试读取或写入 protected 内存

我有这个代码:typedefstruct{stringfName;stringstr;}t;//-------Otherfunctions------//voidBeginTh(){stringarg="yes";t*arglist;arglist=(t*)malloc(sizeof(t));arglist->fName="comBomber";arglist->str=arg;_beginthread(startOver,0,(void*)arglist);free(arglist);}然后在'arglist->fName="comBomber";'我得到这个错误:Anunhandl

c++ - 返回值优化 : ho can I avoid copy construction of huge STL containers.

当我想要一个函数返回一个容器时:vectorfunc(){vectorresult;...returnresult;}按以下方式使用:vectorresult=func();为了避免复制我的容器的开销我经常编写函数,以便它只返回接受一个容器的非常量实例。voidfunc(vector&result){result.clear();...result;}按以下方式使用:vectorresult;func(result);难道我的努力没有意义,因为我可以确定编译器总是使用返回值优化? 最佳答案 没有意义。你提到的RVO类型称为命名RVO

c++ - 使用 googletest 测试 protected 成员

我对谷歌测试时的继承感到困惑。我有一个具有protected属性的A类。如果我想访问那些我必须扩展那个类,但同时我还需要扩展public::testing::Test用于gtest的唯一目的.这个问题最优雅的解决方案是什么?我也试图避免#defineprotectedpublic 最佳答案 为避免在被测类中留下测试痕迹,请使用夹具的多重继承:classToBeTested{protected:boolSensitiveInternal(intp1,intp2);//Stillneedstesting}//Google-test:cl

c++ - std::copy 和 std::vector 问题

我明白为什么这会导致段错误:#include#includeusingnamespacestd;intmain(){vectorv;intiArr[5]={1,2,3,4,5};int*p=iArr;copy(p,p+5,v.begin());return0;}但为什么这不会导致段错误?#include#includeusingnamespacestd;intmain(){vectorv;intiArr[5]={1,2,3,4,5};int*p=iArr;v.reserve(1);copy(p,p+5,v.begin());return0;} 最佳答案

c++ - 使用 std::ifstream、std::istream_iterator 和 std::copy 不读取整个文件

我在一个188字节的文件中使用了以下代码:std::ifstreamis("filename",std::ios::binary);std::vectorbuffer;std::istream_iteratori_input(is);std::copy(i_input,std::istream_iterator(),std::back_inserter(buffer));std::cout但是它只读取了188个字节中的186个字节。我已经在十六进制编辑器和ls-al中确认了文件大小。 最佳答案 我不知道为什么,但默认情况下似乎会跳过