草庐IT

has_public_member_foo

全部标签

c++ - boost Asio : waiting until thread_group has processed all posted tasks?

我有一个对象,一旦创建就会在后台执行许多任务,但应该阻塞直到/所有/发布的任务完成。即:structrun_many{boost::asio::io_servicem_io_service;boost::thread_groupm_threads;boost::asio::signal_setm_signals;voidevaluate(std::stringwork,inti){/*...*/}voidrun_tasks(inttasks,std::stringwork){{boost::asio::io_service::workw(m_io_service);//for(inti

c++ - 为什么 Visual Studio 不在 self 赋值时发出警告 (int foo = foo;)

我在重构一个出现了无数次的术语时不小心产生了如下代码中的情况:#include"stdafx.h"#includeintfoo=foo;//Byreplacingwiththefollowinginstructionwecausesacompileerror//intfoo(foo);int_tmain(intargc,_TCHAR*argv[]){intbar=bar;std::cout对于不同的调试和发布配置,编译器对intfoo=foo;保持沉默。我看不出这种说法不是等待发生的错误。VisualStudio编译器不应该发出警告吗?我并不是假装这是未定义的行为。我的意思是,默认情况

c++ - 使用前向声明时如何修复 "field has incomplete type"错误

如注释中所述,此代码抛出编译器错误error:field‘fTarget’hasincompletetype。为什么会这样?我只是分配那个字段而不做任何需要知道里面是什么的操作......或者我是?也许它无法弄清楚复制构造函数?classFSRVertex;//fwdclassFSREdge{public:charfC;FSRVertexfTarget;//compilererrorFSREdge(charc,FSRVertextarget):fC(c),fTarget(target){}//compilererror};classFSRVertex{public:boost::uno

c++ - 可见性生效时如何导出公共(public)内部/嵌套类?

我正在整理一个补丁,增加了Crypto++library的可见性.根据GCCVisibility维基:Exceptioncatchingofauserdefinedtypeinabinaryotherthantheonewhichthrewtheexceptionrequiresatypeinfolookup...However,thisisn'tthefullstory-itgetsharder.Symbolvisibilityis"default"bydefaultbutifthelinkerencountersjustonedefinitionwithithidden-justo

c++ - vector动态内存分配之private member vector

我是C++新手(我学过Fortran编程),我想为多维表动态分配内存。该表是私有(private)成员变量:classtheclass{public:voidsetdim(void);private:std::vector>thetable;}我想用函数setdim()设置表格的尺寸。voidtheclass::setdim(void){this->thetable.assign(1000,std::vector(2000));}我编译这个程序没有问题,但是当我执行它时,我遇到了一个段错误。对我来说奇怪的是,这段代码(见下文)完全符合我的要求,只是它没有使用我类的私有(private)

C++ 64 位 - 无法读取符号 : Archive has no index; run ranlib to add one

我正在尝试使用静态库在LinuxRHAS5.364位上生成一个非常简单的二进制文件。test1.cpp,生成的.o将被嵌入到静态库中。voidctest1(int*i){*i=5;}和prog.cpp#includevoidctest1(int*);intmain(){intx;ctest1(&x);printf("Valx=%d\n",x);return0;}如果我用32位编译,没问题:--(0931:Wed,06Apr11:$)--g++-m32-Wall-cctest1.cpp--(0931:Wed,06Apr11:$)--filectest1.octest1.o:ELF32-b

c++ - 用公共(public)部分压缩字符串

我有一个管理大量字符串的应用程序。字符串是一种类似路径的格式,有很多共同的部分,但没有明确的规则。它们不是文件系统上的路径,但可以这样考虑。我显然需要优化内存消耗,但又不能牺牲很大的性能。我正在考虑2个选项:-实现一个compressed_string类来存储压缩数据,但我需要一个固定的字典,我现在找不到一个库。我不想要字节上的霍夫曼,我想要文字上的。-在字符串部分实现某种享元模式。这个问题看起来很常见,我想知道最好的解决方案是什么,或者是否有人知道针对这个问题的库。谢谢 最佳答案 虽然针对您的问题调整特定算法可能很诱人,但这可能需

c++ - 来自两个以上字符串的最长公共(public)子字符串 - C++

我需要从C++中的一组文件名中计算最长的公共(public)子字符串。准确地说,我有一个std::strings的std::list(或QT等价物,也很好)charconst*x[]={"FirstFileWord.xls","SecondFileBlue.xls","ThirdFileWhite.xls","ForthFileGreen.xls"};std::listfiles(x,x+sizeof(x)/sizeof(*x));我需要计算所有字符串的n个不同的最长公共(public)子串,在这种情况下,例如对于n=2"File"and".xls"如果我可以计算最长的公共(publi

c++ - 公共(public)接口(interface)方法的私有(private)实现

这个问题在这里已经有了答案:OverridingpublicvirtualfunctionswithprivatefunctionsinC++(7个答案)关闭6年前。我遇到过一段代码,其方法通过公共(public)接口(interface)公开,而实现是私有(private)的。我不确定预期的行为应该是什么。简化示例:#includeclassInterface{public:virtual~Interface(){}virtualvoidmyIfMethod()=0;};classDerived:publicInterface{private:voidmyIfMethod(){std

c++ - VC++ 警告 C4356 : static data member cannot be initialized via derived class

以下代码发出此警告,但它似乎工作正常,因为A::st和B::st都已初始化并且实际上代表相同的字符串。据我了解,这是格式错误的代码,不应编译(我检查了clang)。我想知道为什么VC++不发出错误而是发出警告?#include#includeclassA{public:staticconststd::stringst;};classB:publicA{};conststd::stringB::st="abcd";//warningC4356:'A::st':staticdatamembercannotbeinitializedviaderivedclassintmain(){std::