草庐IT

inner-classes

全部标签

c++ - C/C++ : passing a struct/class with a member array to a function by value

structA{intV[100];};voidf(Aa){a.V[0]=30;}intmain(){Aa;a.V[0]=10;f(a);cout我期望30作为输出,但我得到了10。我知道,如果参数是按值传递的,数组(也是类/结构的成员)也是按引用传递的。相反,当成员时,它们似乎是通过拷贝传递的。是真的吗? 最佳答案 按值将数组作为参数传递给函数会导致它衰减为指向第一个元素的指针,这就像按引用传递一样。将一个包含数组(不是指针)的对象按值传递给函数会导致该对象(包括数组)被复制到函数的参数中。如果您想在调用站点看到该修改,请通过非常

c++ - 初学者 c++ : virtual functions in a base class

我正在编写一些代码,其中我定义了以下基类。classChorus{public://Destructorvirtual~Chorus();//callbackfunctionvirtualintcallback(void*outputBuffer,void*notUsed,unsignedintnBufferFrames,doublestreamTime,RtAudioStreamStatusstatus,void*userData);virtualvoidinitializeDelayBuffer(void);virtualvoiddestroyDelayBuffer(void);}

C++ : How to ensure that a class member variable is modifiable only within a certain method

我在MacOSSierra上使用带有clang的C++14。我想通过设计来执行规则。以下是规则。我的类中有一个成员变量说:unsignedintm_important_num;我的类中有4个方法。fun1();fun2();fun3();fun4();目标:我只希望fun2()能够更改m_important_num的值。问题:如果fun2()以外的任何方法更改变量,是否有可能使其成为编译器错误?一种可能的方法是将其声明为const以某种方式授权fun2()更改const变量?这是一个好的解决方案吗?或者他们有更好的解决方案吗?次要问题:尝试做这样的事情是错误的设计吗?

c++ - 同一个类(class),不同的尺寸......?

看代码,你就明白我的困惑了。测试.hclassTest{public:#ifndefHIDE_VARIABLEintm_Test[10];#endif};啊啊啊classTest;intGetSizeA();Test*GetNewTestA();Aho.cpp//#defineHIDE_VARIABLE#include"Test.h"#include"Aho.h"intGetSizeA(){returnsizeof(Test);}Test*GetNewTestA(){returnnewTest();}Bho.hclassTest;intGetSizeB();Test*GetNewTes

c++ - <function> 不是 <class> 的成员

我已将我的函数“Credit”声明为带有一些参数的私有(private)成员。我的观察是,每当我尝试不带任何参数进行编译时,编译器都会成功编译。但是一旦我用函数中的参数进行编译,编译器就会报错'Transaction::Credit'isnotamemberof'Transaction'这是我的代码classTransaction:publicMenu{private:voidCredit(intdepost);//{return0;}public:voidDeposit();voidWithdraw(){}voidTransfer(){}};voidTransaction::Depo

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

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

c++ - Visual C++ 中同名内部类的问题

我在使用VisualC++2005时遇到了一个问题,其中具有相同名称但在不同外部类中的内部类显然是混淆的。问题发生在两层,每一层都有一个监听器接口(interface)作为内部类。B是A的监听器,并且在其上方的第三层(未显示)有自己的监听器。代码结构如下:啊啊classA{public:classListener{public:Listener();virtual~Listener()=0;};//...};B.hclassB:publicA::Listener{classListener{public:Listener();virtual~Listener()=0;};//...};

添加ng class的课程单击孩子的父母

我有以下问题。我需要设置active与父母的课div从ChildDiv点击,该父母内部。为了说明我将提供一个代码。并省略它的一部分以确保可读性。html...SelectCSS.selected{border:2pxsolid#ffbe10;}.selected-cta{background-color:#ffbe10;}如你所见,我有offer__container获取一些数据并进行NG重复,我需要能够点击offer__container__cta添加active样式对父容器的样式,并跟踪,就像我单击另一个div通过NG重复渲染,应采用主动样式并将其转移到该div。最好还是想设置某些样式of

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