草庐IT

argument-less

全部标签

c++ - 为什么 Sortable 概念需要完全有序的值类型,而 std::sort 只需要 "less than"可比较?

在latestpaperonconceptsN3701,有以下示例与sort算法:templaterequiresSortable()voidsort(Cont&cont)在哪里Sortable概念定义为templateconceptboolSortable(){returnPermutable_container()&&Totally_ordered>();}在哪里Totally_ordered,毫不奇怪,被定义为templateconstexprboolTotally_ordered(){returnWeakly_ordered()&&Equality_comparable();}

c++ - 对类方法进行指针部分特化时获取 "illegal use of explicit template arguments"

您好,我遇到了部分特化的问题。我想要做的是有一个具有模板成员函数的类,该函数将给定值解释为用户指定的值。例如,类名是Value,这是我想做的一个片段:int*ptr1=newint;*ptr1=10;Valueval1=ptr1;int*ptr2=val1.getValue();Valueval2=1;inttestVal=val2.getValue();这是我实现此类的方式:structValue{Value(void*p):val1(p){}Value(inti):val2(i){}templateTgetValue();void*val1;intval2;};templateT*

c++ - 错误 : passing 'const …' as 'this' argument of '…' discards qualifiers

error:passing'constA'as'this'argumentof'voidA::hi()'discardsqualifiers[-fpermissive]我不明白为什么会出现这个错误,我没有返回任何东西,只是传递了对象的引用,就是这样。#includeclassA{public:voidhi(){std::cout@edit我使用const正确性修复了它,但现在我试图在同一个方法中调用方法,我得到了同样的错误,但奇怪的是我没有传递对这个方法的引用。#includeclassA{public:voidsayhi()const{hello();world();}voidhel

c++ - 使用 std::greater 或 std::less 作为参数的参数

我想创建一个函数,其参数接受std::greater或std::less作为论据。不过,我坚持使用参数的语法。这是我尝试过的格式:myFunction(inta,intb,bool*comp(int,int)){…}…std::greaterbigger;myFunction(2,3,bigger);但这不起作用,我怀疑第三个参数完全错误。它实际上应该是什么?cannotconvertstd::greatertobool*(*)(int,int) 最佳答案 采用比较器的函数通常通过模板实现:templatemyFunction(in

c++ - "missing template argument"是什么意思?

我对C++和这个站点还很陌生,所以肯定会出现错误。当我尝试编译我的代码时,我会收到类似error:missingtemplateargumentbefore'b'之类的错误。几个小时以来,我一直在世界各地寻找答案,结果把我带到了这里。我的任务是实现一个模板化的类Collection来存储一个集合使用数组的对象,沿与集合的当前大小。#include#include"collection.h"usingnamespacestd;vintmain(intargc,char*argv[]){collectionb;//#ifndefCOLLECTION_H#defineCOLLECTION_H

c++ - C/C++ : Calling function with no arguments with function which returns nothing

为什么不能调用不带参数的函数,而函数调用作为不返回任何值的参数(恕我直言,这相当于调用不带参数但不带参数的函数)。例如:voidfoo(void){...}voidbar(void){...}foo(bar())不要误会我的意思,我知道void不是一个值,它不能被视为一个值。按照我的逻辑,这是有道理的,应该可以做到。我的意思是,为什么不呢?有什么理由认为这是不可能的吗? 最佳答案 我不相信我听到的任何理由都是好的。看,在C++中,您可以返回void函数的结果:voidfoo(){//...}voidbar(){//...return

c++ - 为什么 std::function::argument_type 已被弃用?

我在cppreference上见过std::function::argument_type在C++17中已被弃用。背后的原因是什么?什么ISOWG21论文提出了这个建议? 最佳答案 相关论文是P0005R4(这是被投票纳入标准草案的论文)和P0090R0(由P0005R4引用)。来自P0090R0的报价:Q2.What'swrongwithresult_type,etc.?A2.TheseC++98/03/TR1-eratypedefspredateddecltypeandperfectforwarding.Previously,g

c++ - 良好做法 : Default arguments for pure virtual method

我创建了一个抽象基类,它有一个带有默认参数的纯虚方法。classBase{...virtualsomeMethod(constSomeStruct&t=0)=0;...}classDerived:publicBase{...virtualsomeMethod(constSomeStruct&t=0);...}所以我想知道将默认参数设置为纯虚拟方法并将整体设置为虚拟方法是一种好习惯吗? 最佳答案 实际上,您的代码是默认参数最糟糕的使用模式之一,因为它涉及继承和多态行为。我支持查看相关的ScottMeyers提示的建议,但这里有一个简短

node.js - Bcrypt 错误 : illegal arguments String unidentified

这是我的完整代码varexpress=require('express'),app=express(),mongoose=require('mongoose'),bodyParser=require('body-parser'),morgan=require('morgan'),webToken=require('jsonwebtoken'),bcrypt=require('bcryptjs'),assert=require('assert');Schema=mongoose.Schema,secretKey="omjdiuwkslxmshsoepdukslsj";//UserSche

node.js - 错误 : Argument "data" is not a valid Document. 输入不是纯 JavaScript 对象

我收到了错误Error:Argument"data"isnotavalidDocument.InputisnotaplainJavaScriptobject.更新文档时,使用firebaseadminSDK。这里是Typescript代码。varmyDoc=newMyDoc();myDoc.Public.Name="JonhDoe"//setupupcontentadmin.firestore().collection('MyDocs').doc("Id1").set(myDoc); 最佳答案 我做了类似的事情:varmyDoc={