草庐IT

member-functions

全部标签

c++ - boost::function 如何支持不同长度模板参数的模板类

我想使用boost预处理器来声明具有不同模板变量长度的模板类,基本上就像boost::function所做的那样。#if!BOOST_PP_IS_ITERATING#ifndefD_EXAMPLE_H#defineD_EXAMPLE_H#include#include#defineBOOST_PP_ITERATION_PARAMS_1(3,(1,2,"example.h"))#includeBOOST_PP_ITERATE()#elsetemplateclassExample{boost::functionfunc;};#endif上面的代码显然不会工作,因为它在同一个头文件中声明了具

c++ - std::function:参数的严格编译时验证

我想实现一个类,它包含两个带有预定义函数签名的回调。该类具有模板化构造函数,它使用std::bind来创建std::function成员。我预计编译器(g++4.6)会提示如果将签名错误的函数传递给ctor。但是,编译器接受以下内容:callbackc1(i,&test::func_a,&test::func_a);我能理解它为什么这样做。我试图为static_assert构造一个适当的条件,但没有成功。如何通过编译时错误来避免这种情况?#includeusingnamespacestd::placeholders;classcallback{public:typedefstd::fu

读书笔记【头先Python】4. List of Files: Functions, Modules & Files

HowtocreateafunctioninPythonLeaveyour swimclub.py codeopeninVSCode(ifyoulike),thenopenanothernewnotebook,andcallit Files.ipynb.YoualreadyknowhowPython’s import statementworkswiththePSL.Itturnsout import canalsoimportyourcustommodules.And,guesswhat?The swimclub.py fileisaPythonmodule,soyoucanuse impo

C++ 11 绑定(bind) std::function 与存储元组和解包

首先,我对C++11还是比较陌生,所以如果我遗漏了什么,请原谅我的疏忽。所以我想做的基本上是让调用者传入一个函数和该函数的任意参数,将其存储起来,然后稍后异步调用它。似乎有2个主要选项:使用std::bind将std::function绑定(bind)到它的参数(使用可变参数模板获得),然后稍后调用它将参数包转换为一个元组,存储它和std::function,然后再次将元组解压为多个参数并使用它调用函数问题是,一种方法比另一种更好吗?两者之间有优缺点/性能优势吗?谢谢!编辑:根据要求,这里有一个澄清,第一种情况是更早的绑定(bind),我将args绑定(bind)到函数,只要调用者传递

c++ - 错误 : no instance of overloaded function

我正在尝试使用以下代码在我的数据库(SQLServer2008)中插入一些行:CDB.cpp#include"CDB.h"voidCDB::ajouterAlerte(){SqlConnection^mySQLConnection;SqlDataAdapter^myDataAdapter;DataSet^myDataSet;DataRow^myRow;SqlParameter^myParameter;try{mySQLConnection=gcnewSqlConnection("DataSource=NECTARYS-PC;InitialCatalog=MonitoringN;Inte

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++ - std::tr1::function::target<TFuncPtr> 和协变/逆变

因为我喜欢用C#和C++编程,所以我打算实现一个类似C#的事件系统,作为我计划的C++SFML-GUI的坚实基础。这只是我的代码的摘录,我希望这能澄清我的概念://Event.h//STLheaders:#include#include#include//boostheaders:#include#includenamespaceUtils{namespaceGui{#defineIMPLEMENTS_EVENT(EVENTNAME,EVENTARGS)public:\Utils::Gui::IEvent&EVENTNAME(){returnm_on##EVENTNAME;}\prot

c++ - 嵌套的 std::function

有可能有一个std::function吗?返回std::function并使用与其他std::functions递归的各种函数,比如函数的函数?换句话说,我想将一组函数折叠成一个函数。例如脱离基础教程doublegenFunc(doublex,std::functionf){doubleres=f(x);returnres;}doublesquare(doublex){returnx*x;}doubledbl_sq(doublex){returnsquare(x*x);}我如何修改它以允许嵌套std::function电话? 最佳答案

c++ - Qt错误: 'const class QString' has no member named 'toStdString'

我收到此错误error:'constclassQString'hasnomembernamed'toStdString'虽然QString有它。(link).代码std::stringMessage::toStdString()const{returnm_string.toStdString();} 最佳答案 直接从这里复制答案:HowtoconvertQStringtostd::string?QStringqs;//EitherthisifyouuseUTF-8anywherestd::stringutf8_text=qs.toU

c++ - 错误 : Member is inaccessible

我有这两个类:classHand{public:intgetTotal();std::vector&getCards();voidadd(Card&card);voidclear();private:std::vectorcards;};classDeck:publicHand{public:voidrePopulate();voidshuffle();voiddeal(Hand&hand);};哪里shuffle()函数声明如下:voidDeck::shuffle(){std::random_shuffle(cards.begin(),cards.end());}但是,这会返回以下错