草庐IT

For-Each

全部标签

C++/QML : How to define and handle multiple contexts for dynamically created components?

基本上我的情况是这样的:我有一个扩展QQuickView的类,它通过设置上下文属性将某些对象从C++公开到QML。显示的View是从QML创建的,并且都是同一定制组件的不同实例;当某些事件发生时会创建新View,当这种情况发生时,现有View应显示最初在C++端分配给它们的对象,而新View应显示分配给它们的对象。所以,在C++方面,我有这样的东西:WindowManager::WindowManager(QQuickView*parent):QQuickView(parent){//Settingthesourcefiletousethis->setSource(QUrl("qrc:

c++ - 错误 : no matching function for call to ‘to_string(std::basic_string<char>&)’

即使在模板中我可以有任何类型,函数to_string对基本字符串不起作用:例如:std::stringstr("mystring");my_class(str);用这个仿函数定义:templatevoidoperator()(valuetypevalue){...private_string_field=std::to_string(value);不起作用。这是错误:error:nomatchingfunctionforcallto‘to_string(std::basic_string&)’避免它的最佳方法是什么。事先,我要求避免仅仅因为一些常见的关键字就链接到不相关的问题。

c++ - "no matching function for call to ‘async(std::launch, <unresolved overloaded function type>, std::string&)’“

我正在尝试使用std::async创建线程,但我不断收到错误“没有匹配函数调用‘async(std::launch,,std::string&)’”在行上ConnectFuture=std::async(std::launch::async,Connect_T,ip);这是产生这种行为的代码:#includeclasslibWrapper{public:voidConnect(std::stringip);voidConnect_T(std::stringip);private:std::futureConnectFuture;};voidlibWrapper::Connect(std

c++ - DLIB : Training Shape_predictor for 194 landmarks (helen dataset)

我正在使用helen数据集训练DLIB的shape_predictor194个面部标志,该数据集用于通过face_landmark_detection_ex检测面部标志dlib库的.cpp现在它给了我一个sp.dat二进制文件,大约45MB,与给定的文件(http://sourceforge.net/projects/dclib/files/dlib/v18.10/shape_predictor_68_face_landmarks.dat.bz2)相比,它包含68个面部特征点。在训练中平均训练误差:0.0203811平均测试误差:0.0204511当我使用经过训练的数据来获取面部标志位

c++ - 是否可以并行化这个 for 循环?

我得到了一些使用OpenMP进行并行化的代码,在各种函数调用中,我注意到这个for循环在计算时间上有一些好处。doubleU[n][n];doubleL[n][n];doubleAprime[n][n];for(i=0;i=i){doubles;s=0;for(k=0;k然而,在尝试将其并行化并在各处应用一些信号量之后(没有运气),我开始意识到elseif条件对早期的有很强的依赖性if(L[j][i]是一个用U[i][i]处理过的数字,可以在早期的if),在我看来,由于竞争条件,它是不可并行化的。是否可以并行化此代码,使elseif仅在较早的if已经完成时执行?

c++ - 警告 C4661 :no suitable definition provided for explicit template instantiation request

我写了一个类模板并在不同的DLL中使用它,所以希望隐藏部分实现。为此,我使用“模板实例化”,但导出它,像这样,这里是头文件:#include#includeusingnamespacestd;templateclass__declspec(dllexport)Templated{public:Templated();};template__declspec(dllexport)Templated;intmain(){cout并且定义在单独的文件(.cpp)中templateTemplated::Templated(){}templateTemplated;我的问题是我收到警告,即使实例

c++ - 使用 std::for_each 遍历树

我对使用algorithm还很陌生和functional在C++中。我需要进行树遍历并为每个元素执行一个函数。请参阅下面的代码。这行得通,但我有一些我不喜欢的东西,也许可以做得更好。请注意,我仅限于相当旧的g++(4.4.7)版本,无法使用lambda函数。我使用包装函数do_walk和std::bind调用成员函数walk在每个元素上。有没有办法避开包装函数,直接调用成员函数?我为回调函数使用了typedefUnaryFunction.我更愿意使用walk的模板化版本.但是,当我更改代码以使用模板时,出现以下编译错误:error:nomatchingfunctionforcallto

c++ - 错误 : no matching member function for call to 'push_back'

为什么我在最后两行收到错误?目标是在集合中找到对象,并修改其内容。usingnamespacestd;structmystruct{intid;vectory;mystruct(constintid):id(id){}booloperatorsx;mystructx(1);x.y.push_back(1);x.y.push_back(2);sx.insert(x);//set::iteratori=sx.find(1);constmystruct*x1=&(*i);constmystructx2=*x1;couty)y)y.push_back(4);}好像迭代器返回的是常量对象,不让我

c++ - 在 C++ 的 for 循环中声明结构是否合法?

我刚刚在Gcc编译器中试验了以下程序。我想知道,在for循环中声明结构并在GCC中工作正常。#includeintmain(){inti=0;for(structst{inta{9};}t;i那么,在for循环中声明结构是否合法?DEMO 最佳答案 是的,在for循环(从C99开始)的子句1中声明(带有初始值设定项)是合法的。让我们将您的C++转换为C代码(因为当我写这篇文章时您的问题被标记为“c”):$catx.c#includeintmain(void){for(struct{inta;}t={0};t.a相关C99:6.8.5

c++ - 错误 : no matching function for call to . .. 在返回语句

我在openSUSELeap15上的Qt5.9.4上使用GCC7。我有以下类(class):classManSuppProps:publicQObject{Q_OBJECTpublic:explicitManSuppProps(QStringparentName);explicitManSuppProps(){}explicitManSuppProps(constManSuppProps&manSuppProps);explicitManSuppProps(ManSuppProps&manSuppProps);~ManSuppProps();private:QVector3Dm_sup