草庐IT

parameter_name

全部标签

c++ - CRTP + 特征类 : "no type named..."

我尝试使用模板化类实现CRTP,但在使用以下示例代码时出现错误:#includetemplateclassTraits{public:typedeftypenameT::typetype;//'staticconstunsignedintm_const=T::m_const;staticconstunsignedintn_const=T::n_const;staticconstunsignedintsize_const=T::m_const*T::n_const;};templateclassCrtp{public:typedeftypenameTraits::typecrtp_typ

c++ - 为什么将数组作为 "int *& name"传递?

我得到了一个(C++)代码,其中使用数组传递voidfun(int*&name){...}但这背后的想法是什么?我猜它的意思是“一个引用数组”,但是当你只传递一个指向第一个元素的指针时就没问题了,不是吗?那么这样做的动机是什么? 最佳答案 该函数接收对指针的引用。这意味着该函数不仅可以修改name指向的int,还可以修改自身指针函数调用也将在外部可见。例子:#includeint*allocate(){returnnewint();}voiddestroy(int*&ptr){deleteptr;ptr=NULL;}intmain(

c++ - 获取错误 : 'mutex' in namespace 'std' does not name a type in MinGW mysys prompt

我已经从官方网站下载了MinGW并将其安装在我的Windows8.1机器上。运行g++--version给我g++.exe(GCC)4.8.1。我正在尝试在MinGW编译器中编译现有的代码库,但它因以下错误而失败:error:'mutex'innamespace'std'doesnotnameatypeprivate:std::mutexm_Mutex;^error:'condition_variable'innamespace's还有更多与锁定和线程相关的错误。!我能够在Cygwin-64中编译相同的代码库,没有任何问题。我需要在MinGW中成功构建和编译,以便创建一些与MSVS兼容

c++ - 错误 : Expected template-name before '<' token

我正在尝试编译一个实现chain和chainNodes的程序并在以下行(第22行)出现错误:classchain:publiclinearList错误是:Error:expectedtemplate-namebefore'知道为什么会出现这种情况吗?我的代码如下://linkedimplementationofalinearlist//derivesfromabstractclasslinearListjusttomakesure//allmethodsoftheADTareimplemented#ifndefchain_#definechain_#include#include#in

C++11 : Is it possible to give fixed-template-parameted template to varidic-template-template-parameter?

(是的,由于我糟糕的英语,标题很奇怪;我希望有人能改进它。)接听thisquestion,我发现这段代码有效:templateclassA{};templateclassU>classB{};intmain(){Bit_works;}..虽然templateclass和templateclass不相等。我试图弄清楚为什么这是可能的,并观察了N3337standard的[temp.param],但我找不到任何东西。怎么可能? 最佳答案 是的,这是可能的。C++1114.3.3/3特别允许,并提供了一个例子。3Atemplate-arg

c++ - 多次调用 typeid(T).name() 会返回同一个指针吗?

在C++中,我可以使用typeid运算符来检索任何多态类的名称:constchar*name=typeid(CMyClass).name();返回的constchar*指向的字符串willbeavailabletomyprogramforaslongasthecorrespondingclassexists.typeid(T).name()的多次调用是否会为相同的classT返回相同的指针值,或者它们是否允许返回不同的指针? 最佳答案 不,它们不需要返回相同的指针。我在野外系统也看到过没有。每个DLL都有自己的包含nmae的类型对象

c++ - C/C++ : Naming conventions for arrays?

按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter指导。关闭11年前。数组的良好命名约定是什么?我正在处理一个包含几千行代码的代码库,并且没有一致的数组命名约定。很少有人通过在名称末尾附加List来命名它们,例如*message_list*,我真的不喜欢它,因为它错误地暗示这是一个列表(链表),并且很少有人像messages这样通过在末尾附加“s”来命名它们,这比以前的方法要好,但有时会失败。我想知道数组类型变量是否有任何

解决在idea上连接linux开启的redis服务失败Failed to connect to any host resolved for DNS name.(史上最强+最细解决方案)

今天在idea上连接reids服务器时出现错误FailedtoconnecttoanyhostresolvedforDNSname.那么我们来一步一步来进行如下步骤。首先找到自己的redis.conf文件,可以使用这个搜索按钮直接搜索redis.conf文件(因为不同人的redis.conf文件可能不一样)找到该文件后我们需要修改如下几个地方。(1)、daemonizeyes大概在136行(2)、protected-modeno大概在88行(3)、注释掉bind127.0.0.1大概在69行这里需要注意的是注释的不是上面的而是箭头所指的地方。修改完成后我们wq保存退出。下面是打开端口6379(

C++ 错误 : Type Name is Not Allowed

我正在尝试学习指针参数中的新类(class),我想让函数senior和everyoneElse接受指针x,但是当我尝试使用指针pAge调用函数时,它显示错误:类型名称是不允许的。怎么了?#includeintsenior(int*x);inteveryoneElse(int*x);usingnamespacestd;intmain(){intage(0);int*pAge(&age);cout>age;if(age>59)senior(int*pAge);elseeveryoneElse(int*pAge);return0;}intsenior(int*x){return*x;}int

c++ - 可变参数模板 : Perfect forwarding of integer parameter to lambda

有类似的问题,但我没有找到适合我的问题的答案。考虑以下代码:#include#include#include#include#includeclassTestClass{public:TestClass(intvalue):mValue(value){}private:intmValue;};templateclassDeferredCreator{public:templateDeferredCreator(Args&&...args):mpCreator([=]()->T*{returnnewT(std::forward(args)...);}),mpObject(){}T*get