草庐IT

dynamic-class

全部标签

c++ - dynamic的动态数组(array of struct)

我有一个名为person的结构,如下所示:structperson{intheight,weight;};我还创建了一个person数组,如下所示:structArrayofperson{intlen;//indicatesthelengthofthisarray(itssupposedtobedynamic)person*p;//thisissupposedtobethedynamicarrayofperson.};我对person的数组执行此操作,如下所示:structArray_2d_ofperson{intlen;//indicatesthelengthofthisarray(

c++ - 为什么 dynamic_cast 存在?

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Regularcastvs.static_castvs.dynamic_cast我通过这个问题了解了static_cast的工作原理。Whyisitimportanttousestatic_castinsteadofreinterpret_casthere?但如果static_cast确实知道类的继承关系,为什么dynamic_cast存在?我们什么时候必须使用dynamic_cast?

C++ 将 dynamic_bitset 存储到文件中

跟进Howdoesonestoreavectororabitsetintoafile,butbit-wise?基本上,我使用以下代码将位集编写为二进制文件:boost::dynamic_bitset::block_type>filter;vector::block_type>filterBlocks(filter.num_blocks());//populatevectorblocksboost::to_block_range(filter,filterBlocks.begin());ofstreammyFile(filterFilePath.c_str(),ios::out|ios:

c++ - Uncrustify 在 Class::method 处破坏代码

我正在尝试使用Uncrustify,但在xcode中工作时所有配置都破坏了我的代码std::vectora;成为std::vectora;有没有办法防止这种情况发生,使::保持在一起 最佳答案 此错误的原因是Uncrustify参数中的语言设置错误。将-lOC更改为-lCPP解决了问题 关于c++-Uncrustify在Class::method处破坏代码,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.co

警告:指定的串行端口在第127行上的php_serial.class.php中无效

我试图使用PHP与串行端口进行通信,我的代码是,deviceSet("COM1");$serial->confBaudRate(2400);$serial->confParity("none");$serial->confCharacterLength(8);$serial->confStopBits(1);$serial->confFlowControl("none");$serial->deviceOpen();$serial->sendMessage("Hello!");$read=$serial->readPort();$serial->deviceClose();$serial->c

C++ 类型比较 : typeid vs double dispatch dynamic_cast

是否有任何性能或稳健性原因使您更喜欢其中一个?#include#includestructB{virtualboolIsType(Bconst*b)const{returnIsType2nd(b)&&b->IsType2nd(this);}virtualboolIsType2nd(Bconst*b)const{returndynamic_cast(b)!=nullptr;}};structD0:B{virtualboolIsType(Bconst*b)const{returnIsType2nd(b)&&b->IsType2nd(this);}virtualboolIsType2nd(B

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::

c++ - 对类型的非常量左值引用 - 使用 Class 类型的参数时 Objective-C++ 包装器中的错误

我有两个用Objective-C++编写的包装器类,用于它们等效的C++类。我们称它们为OABCClass和OXYZCallbackInterface。现在我在C++(ABCClass)中有一个方法,其中一个参数是一个接口(interface)-XYZCallbackInterface。例如:std::stringmethodWithArguments(std::stringreq,CommonNamespace::XYZCallbackInterface&callback);在我的Objective-C++包装器类中,即OABCClass我对上述C++方法的方法实现如下所示:-(NS

c++ - C++ 中的继承 : define variables in parent-child classes

问题我正在寻找在父子类中定义变量的最佳方法,以便通过指向其父类的指针进行调用。这是协议(protocol):classBase{public:virtualvoidfunction()=0;};classA:publicBase{public:inta,b;A(inta_,intb_):a(a_),b(b_){};voidfunction(){//dosomething..}};classB:publicBase{public:inta,b;B(inta_,intb_):a(a_),b(b_){};voidfunction(){//dosomething..}};Base*elemen

c++ - 海湾合作委员会 : Specifying static/dynamic libraries to build against

我有一个简单的C++项目,其结构如下:-一个基础项目(即:包含main()),以及针对其他所有内容的链接--一些自定义库,它们都是作为静态库构建的(即:.a文件)---其中一个静态库使用共享目标文件(即:.so文件)中的功能因此,例如,在所有初始编译完成后,项目在链接时将如何显示(在TreeView中):-myApp(themainapplication)--libaudio.a(theaudiolibraryImade)--libnetwork.a(thenetworkinglibraryImade)--libvideo.a(thevideolibraryImade)--libboo