草庐IT

pcap_set_buffer_size

全部标签

c++ - Protocol Buffer : how nested (custom) optional fields are to be handled in C++?

读入ProtocolBufferBasics:C++,没有找到符合情况的东西:;以下.proto处理--cpp_out,messageA{requiredint32foo=1;}messageB{optionalAdata=1;}没有生成明显的访问器/setter来设置自定义可选字段(包括我懒得放在这里的“嵌套类型”部分)://accessors-------------------------------------------------------//optional.A=1;inlineboolhas_a()const;inlinevoidclear_a();staticcon

c++ - 我们什么时候应该为 `std::unordered_set` 提供我们自己的哈希函数

当我编译下面的代码时,我看到了与Hash相关的错误。intF_no_meaningA(unordered_set>&setVec,vector&vec){setVec.insert(vec);return1;}intmain(){vectorW{2,3,7};unordered_set>setVec;}$g++--versiong++(Ubuntu/Linaro4.6.3-1ubuntu5)4.6.3$g++$1.cpp-o$1-g-Wall-Weffc++-pedantic-std=c++0x/tmp/ccCQFQ4N.o:Infunction`std::__detail::_Has

c++ - vector < vector > : verify that all have equal sizes

是否有std/boost算法来验证一个vector中的所有vector是否具有相同的大小?推而广之,所有元素的属性都相同吗?在下面的示例中,我使用了我正在寻找的假设的std::all_equal:typedefstd::vectorLine;std::vectorlines;lines.push(Line(10));lines.push(Line(11));autoequalLengths=std::all_equal(lines.begin(),lines.end(),[](constLine&x){returnx.size();});(并且通过扩展:std::vectorvec;a

c++ - 具有自定义结构的 <set> 包含重复项

我一直在学习C++。我被这个问题困住了。我有一个包含自定义结构的集合,该结构包含两个longint的a和b。我有一个自定义比较器结构,用于比较数字并在a或b不同时返回true。typedeflongintli;structnumber{number(lia1,lib1):a(a1),b(b1){}lia,b;};structcompare{booloperator()(constnumber&lhs,constnumber&rhs)const{returnlhs.a!=rhs.a||lhs.b!=rhs.b;}};intmain(){setnums;nums.insert(number

c++ - 通过与不同类型的值进行自定义比较来查找 std::set 的元素

考虑以下带有自定义比较器的std::set玩具示例:#includestructA{A():a(cnt++){}constinta;staticintcnt;};intA::cnt=0;structcomp{booloperator()(constA&left,constA&right){returnleft.asa;for(inti=0;i请注意,A不能简单地从整数创建。我想在sa中寻找给定值为A::a的A,无需构造aA类型的临时对象,即我正在搜索类似的东西sa.find(4)带有自定义比较器,允许直接比较整数与A类型的对象。这可能吗? 最佳答案

c++ - size_t 在哪里定义的?

所以我知道CCompatabilityHeaders中的任何标题:Placesintheglobalnamespaceeachnamethatthecorrespondingcxxxheaderwouldhaveplacedinthestdnamespace我还知道这些C头文件自c++17起已被弃用。,支持它们的兼容性“cxxx”对应物。现在,我相信size_t完全由StandardDefinesHeader定义.所以我认为这在技术上意味着全局命名空间中size_t的定义已被弃用?多年来我一直将它用作size_t,在我开始使用std::size_t之前,我希望得到确认。

c++ - 编译错误 - std::set with const 成员

我这辈子都弄不明白这段代码有什么问题:ClassA&doSomething(std::setconst>const&someSet){std::set>secondSet;for(std::setconst>::const_iteratorit=someSet.begin();it!=someSet.end();it++){if(checkSomething(*it))secondSet.insert(boost::const_pointer_cast(*it));}}当我尝试编译时,在g++的第4行(for循环的开始)出现以下错误:/usr/include/c++/4.4/ext/n

c++ - `size` 来自哪里?

我知道在某个地方应该有一个我不关心的删除运算符。我只是想知道,哇,它奏效了。“大小”的说法从何而来?#include#includeclassBase{public:Base(){}void*operatornew(unsignedintsize,std::stringstr){std::cout结果如下:记录新对象“基本实例1”的16字节分配 最佳答案 由编译器在编译时提供。当编译器看到:new("Baseinstance1")Base;它将添加一个调用:Base::operatornew(sizeof(Base),"Basein

c++ - Google Protocol Buffers C++ 实现在面对恶意数据时的稳定性和安全性

对于使用GoogleProtocolBuffersC++实现的人来说,它如何处理恶意或格式错误的消息?例如,它会崩溃还是继续运行?我的应用程序肯定会在某个时候收到恶意数据,我不希望每次收到格式错误的消息时它都崩溃。这是我在这个问题上能找到的唯一答案(googlemailinglist)。Therewasareviewspecificallyforsecurityissuesbeforethecodewasreleased.ForatleasttheC++andJavaimplementations,therearevarioussafeguardstoprotectagainstcor

c++ - 到处使用 std::size_t 是一种好习惯吗?

这个问题在这里已经有了答案:关闭12年前。PossibleDuplicate:Whentousestd::size_t?我的代码中有很多常量是无符号数,例如计数器、截止频率、长度等。我开始对所有这些使用std::size_t,而不是int或unsignedint。这样做对吗?我启动它是因为STL容器将它用于它们的大小,它用于字符串位置等。