草庐IT

C++ unique_ptr 和映射

我正在尝试使用C++0xunique_ptrclass在map内像这样://compilewith`g++main.cpp-std=gnu++0x`#include#include#includeusingnamespacestd;structFoo{char*str;Foo(charconst*str_):str(strdup(str_)){}};intmain(void){typedefstd::map>Bar;Barbar;autoa=bar.insert(Bar::value_type(1,newFoo("one")));return0;}但是GCC给了我以下错误(缩短,我认为

c++ - 为什么我要 std::move 一个 std::shared_ptr?

我一直在看Clangsourcecode我发现了这个片段:voidCompilerInstance::setInvocation(std::shared_ptrValue){Invocation=std::move(Value);}我为什么要std::move一个std::shared_ptr?转让共享资源的所有权有什么意义吗?我为什么不这样做呢?voidCompilerInstance::setInvocation(std::shared_ptrValue){Invocation=Value;} 最佳答案 我认为其他答案没有足够强

c++ - std::auto_ptr 到 std::unique_ptr

随着新标准的到来(以及某些编译器中已经提供的部分),新类型std::unique_ptr应该是std::auto_ptr的替代品.它们的用法是否完全重叠(所以我可以对我的代码进行全局查找/替换(不是我会这样做,但如果我这样做了))或者我是否应该知道一些从阅读中不明显的差异文档?另外如果是直接替换,为什么要给它一个新名字而不是仅仅改进std::auto_ptr? 最佳答案 您无法进行全局查找/替换,因为您可以复制auto_ptr(具有已知后果),但只能移动unique_ptr。任何看起来像的东西std::auto_ptrp(newin

c++ - 为什么我不能将 unique_ptr 推回 vector 中?

这个程序有什么问题?#include#includeintmain(){std::vector>vec;intx(1);std::unique_ptrptr2x(&x);vec.push_back(ptr2x);//Thistinycommandhasaviciouserror.return0;}错误:Infileincludedfromc:\mingw\bin\../lib/gcc/mingw32/4.5.0/include/c++/mingw32/bits/c++allocator.h:34:0,fromc:\mingw\bin\../lib/gcc/mingw32/4.5.0/i

c++ - boost::serialization 如何与 C++11 中的 std::shared_ptr 一起使用?

我知道有aBoostmodule对于serialization的boost::shared_ptr,但我找不到std::shared_ptr的任何内容.另外,我不知道如何轻松实现它。恐怕下面的代码namespaceboost{namespaceserialization{templateinlinevoidserialize(Archive&ar,std::shared_ptr&t,constunsignedintversion){if(Archive::is_loading::value){T*r;ar>>r;t=r;}else{ar不起作用。事实上,如果某个对象被多次引用,它会在第

c++ - boost::serialization 如何与 C++11 中的 std::shared_ptr 一起使用?

我知道有aBoostmodule对于serialization的boost::shared_ptr,但我找不到std::shared_ptr的任何内容.另外,我不知道如何轻松实现它。恐怕下面的代码namespaceboost{namespaceserialization{templateinlinevoidserialize(Archive&ar,std::shared_ptr&t,constunsignedintversion){if(Archive::is_loading::value){T*r;ar>>r;t=r;}else{ar不起作用。事实上,如果某个对象被多次引用,它会在第

c++ - 诠释 x;整数y;诠释*ptr;不是初始化吧?

我正在阅读J.P.Mueller和J.Cogswell的“C++All-in-OneforDummies”,偶然发现:#includeusingnamespacestd;intmain(){intExpensiveComputer;intCheapComputer;int*ptrToComp;...Thiscodestartsoutbyinitializingallthegoodiesinvolved—twointegersandapointertoaninteger.确认一下,这是一个错误,应该读作“...通过声明”,对吗?让我感到奇怪的是,这些基本错误仍然会出现在书籍中。

c++ - 诠释 x;整数y;诠释*ptr;不是初始化吧?

我正在阅读J.P.Mueller和J.Cogswell的“C++All-in-OneforDummies”,偶然发现:#includeusingnamespacestd;intmain(){intExpensiveComputer;intCheapComputer;int*ptrToComp;...Thiscodestartsoutbyinitializingallthegoodiesinvolved—twointegersandapointertoaninteger.确认一下,这是一个错误,应该读作“...通过声明”,对吗?让我感到奇怪的是,这些基本错误仍然会出现在书籍中。

html - Force to open "Save As..."popup open at text link click for PDF in HTML

我的网站上有一些大尺寸的PDF目录,我需要将它们链接为下载。当我用谷歌搜索时,我发现下面提到了这样的事情。它应该会在点击链接时打开“SaveAs...”弹出窗口......但它不起作用:/当我链接到如下文件时,它只是链接到文件并试图打开文件。Filename更新(根据下面的答案):据我所知,没有100%可靠的跨浏览器解决方案。可能最好的方法是使用下面列出的网络服务之一,并提供下载链接...http://box.net/http://droplr.com/http://getcloudapp.com/ 最佳答案 来自对的回答Force

php - 网址缩短 : using inode as short name?

我正在处理的网站希望生成自己的缩短URL,而不是依赖于tinyurl或bit.ly等第三方。显然,我可以在将新URL添加到站点时对它们进行计数,并使用它来生成短URL。但如果可能的话,我会尽量避免这种情况,因为要让这件事发挥作用似乎需要做很多工作。由于需要短URL的东西都是网络服务器上的真实物理文件,我当前的解决方案是使用它们的inode编号,因为这些编号已经生成供我使用并保证是唯一的。functionshort_name($file){$ino=@fileinode($file);$s=base_convert($ino,10,36);return$s;}这似乎有效。问题是,我该怎么