草庐IT

member-variables

全部标签

c++ - "cast to first member of standard layout"类型双关规则是否扩展到数组?

具体来说,我将CAPI包装在一个友好的C++包装器中。CAPI具有这种相当标准的形式:structfoo{...};voidget_foos(size_t*count,foo*dst);我想做的是,通过将类型双关的包装器数组直接传递给Capi来为自己保存一个额外的拷贝,并保持理智检查static_assert().classfooWrapper{fooraw_;public:[...]};std::vectorget_foo_vector(){size_tcount=0;get_foos(&count,nullptr);std::vectorresult(count);//Isthis

C++ 私有(private)函数 : Whether to pass class member variable by function parameter, 或不

这是一个在C++类实现中反复出现的问题。我很好奇人们在这里的想法是什么。您更喜欢哪种代码,为什么?classA{public:/*Constructors,Destructors,Publicinterfacefunctions,etc.*/voidpublicCall(void);private:voidf(void);CMyClassm_Member1;};与voidA::publicCall(void){f();}voidA::f(void){//dosomestuffpopulatingm_Member1}或者替代方案:classA{public:/*Constructors,

c++ - Visual Studio 2015 "non-standard syntax; use ' &' to create a pointer to member"

我正在尝试用C++实现自己的链表,但终究无法弄清楚为什么会出现此错误。我知道有一个STL实现,但出于某种原因,我正在尝试自己的实现。这是代码:#includetemplateclassListElement{public:ListElement(constT&value):next(NULL),data(value){}~ListElement(){}ListElement*getNext(){returnnext;}constT&value()const{returnvalue;}voidsetNext(ListElement*elem){next=elem;}voidsetValu

c++ - 线程错误 : invalid use of non-static member function

这个问题在这里已经有了答案:Passingmemberfunctionstostd::thread[duplicate](2个答案)关闭5年前。我想了解C++中的线程,但我不知道如何解决这个问题。我想调用两个线程来运行名为“createS”的函数,但出现此错误:error:invaliduseofnon-staticmemberfunction我读过关于这个主题的其他问题,但我真的不明白如何让我的代码工作。有人可以向我解释我做错了什么并尝试帮助我找到解决方案吗?test_class.cppvoidtest_class::generateS(){map1=newmultimap>;map

c++ - 微优化 : iterating with local variable vs. 类成员

我认为如果我将迭代变量声明一次作为类成员,我会节省一些时间:structFoo{inti;voidmethod1(){for(i=0;i然而,这似乎快了20%structFoo{voidmethod1(){for(inti=0;i在这段代码中voidloop(){//Arduinoloopsfoo.method1();foo.method2();}您能解释一下性能差异吗?(我需要在Arduino上运行许多简单的并行“进程”,这种微优化会产生影响。) 最佳答案 当您在循环内声明循环变量时,它的范围非常狭窄。编译器可以随时将其保存在寄存

我的类中的 c++ condition_variable wait_for 谓词,std::thread <unresolved overloaded function type> error

我想在我的类中使用一个线程,然后该线程需要使用一个condition_variable,条件变量将被阻塞,直到一个谓词被更改为true。代码如下所示:classmyThreadClass{boolbFlag;threadt;mutexmtx;condition_variablecv;boolmyPredicate(){returnbFlag;}intmyThreadFunction(intarg){while(true){unique_locklck(mtx);if(cv.wait_for(lck,std::chrono::milliseconds(3000),myPredicate)

c++ - 编译错误error C2039 : 'clock_t' : is not a member of '` global namespace''

我在VS2010中使用boost1_53进行编译。我也在使用boost的线程。在编译过程中我遇到了一堆这样的错误c:\programfiles(x86)\microsoftvisualstudio10.0\vc\include\ctime(18):errorC2039:'clock_t':isnotamemberof'`globalnamespace''所有错误都是关于ctime和c_time.hpp。我四处寻找解决方案但没有成功。谁能帮忙吗?这里是部分代码。#defineBOOST_THREAD_USE_DLL#include#include#include#include#incl

c++ - "variable tracking"占用了我的编译时间!

我有一个自动生成的文件,看起来像这样......staticvoiddo_SomeFunc1(void*parameter){//Dostuff.}//Continuesonforanother4000functions...voiddispatch(intid,void*parameter){switch(id){case::SomeClass1::id:returndo_SomeFunc1(parameter);case::SomeClass2::id:returndo_SomeFunc2(parameter);//Thiscontinuesforthenext4000cases.

c++ - 这个 AnonymousClass(variable) 声明中到底发生了什么?

尝试编译:classAnonymousClass{public:AnonymousClass(intx){}};intmain(){intx;AnonymousClass(x);return0;}从MSVC生成错误:foo.cpp(13):errorC2371:'x':redefinition;differentbasictypesfoo.cpp(12):seedeclarationof'x'foo.cpp(13):errorC2512:'AnonymousClass':noappropriatedefaultconstructoravailableg++的错误信息类似:foo.cpp

android - 错误 : 'to_string' is not a member of 'std'

它可能是重复的,但我尝试了我在StackOverflow内外找到的所有解决方案。我正在使用OpenCV在C++上创建一个库,并尝试为Android编译它。我不能使用to_string(int)但我不能。我试图多次修改我的makefile。我最后的配置是:Android.mkLOCAL_PATH:=$(callmy-dir)include$(CLEAR_VARS)OPENCV_CAMERA_MODULES:=offOPENCV_INSTALL_MODULES:=oninclude$(LOCAL_PATH)/jsoncpp/Android.mkinclude/Users/rafaelrui