草庐IT

out_of_sample_df

全部标签

C++14 元编程 : Automagically build a list of types at compile/init time

使用C++14和CuriouslyRecurringTemplatePattern(CRTP)以及可能的Boost.Hana的某种组合(或boost::mpl如果您愿意),我可以在编译时(或静态初始化时)构建一个类型列表而无需显式声明吗?例如,我有这样的东西(在Coliru上查看):#include#include#includenamespace{structD1{staticconstexprautoval=10;};structD2{staticconstexprautoval=20;};structD3{staticconstexprautoval=30;};}intmain(

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

我在将仿函数从Windows移植到Linux时遇到问题。(传递给STL::map以进行严格弱排序的仿函数)原文如下:structstringCompare{//Utilizedasafunctorforstl::mapparameterforstringsbooloperator()(stringlhs,stringrhs){//Returnstrueiflhs由于linux不支持_stricmp而是使用strcasecmp,我将其更改为:structstringCompare{booloperator()(stringlhs,stringrhs){//Returnstrueiflhs

C++ 连接字符串导致 "invalid operands of types ‘const char*’ 和 ‘const char"

我想连接两个字符串,但出现错误,我不知道如何克服这个错误。有什么方法可以将这个constchar*转换为char吗?我应该使用一些取消引用吗?../src/main.cpp:38:error:invalidoperandsoftypes‘constchar*’and‘constchar[2]’tobinary‘operator+’make:***[src/main.o]Error1但是,如果我尝试以这种方式组成“bottom”字符串,它会起作用:bottom+="|";bottom+=tmp[j];bottom+="";这是代码。#include#include#include#inc

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

c++ - 编译错误 : base operand of ‘->’ has non-pointer type ‘Token’

我在尝试编译我的C++代码时遇到标题中提到的错误。我无法理解我在这里做错了什么。编译器在我执行booloperator==(Token)函数时出现问题。我认为这是使运算符(operator)重载的方法。关于为什么编译器不喜欢我提到的任何线索this->terminal还是this->lexeme?classToken{public:tokenTypeterminal;std::stringlexeme;Token*next;Token();booloperator==(Token&t);private:intlexemelength,line,column;};boolToken::o

c++ - std::result_of 用于内置运算符

通过result_of确定诸如-int()或double()*double()之类的结果的正确语法是什么?失败std::result_of::typestd::result_of::type 最佳答案 std::result_of真的不是这里采取的方法。decltype做你想做的,可以用作decltype(-int()),decltype(double()*double())等等如果你不知道类型是否是默认构造的,你也可以使用std::declval:decltype(-std::declval()).任何语法涉及operator-的

c++ - "Use of undefined type"带有 unique_ptr 以转发声明的类和默认移动构造函数/赋值

在下面的代码中,是避免编译错误并在A.cpp中手动包含B.h实现移动构造函数/赋值的唯一方法吗?//A.h#includeclassB;//implementationsomewhereinB.h/B.cppclassA{public:A()=default;~A()=default;A(constA&)=delete;A&operator=(constA&)=delete;A(A&&)=default;A&operator=(A&&)=default;private:std::unique_ptrm_b;};VisualStudio2015给出“错误C2027:使用未定义类型”,因为

c++ - 'giving out' 是构造函数中对 'this' 的引用吗?

我的代码:Scene::Scene(conststd::string&scene_file):ambient_light(0,0,0),background(0,0,0){scene_parserparser(*this);parser.parse(scene_file);}scene_parser是Scene的friend,在parse方法中它访问(r/w)Scene的成员。这会导致任何问题吗? 最佳答案 是的,给出对this的引用是可以的。但是,您通常希望在其他对象稍后使用该指针时执行此操作。您的用例看起来会在构造函数完成之前立

c++ - 拼图 : To escape the check of typeid

我偶然形成了一个很好的面试问题。:)templateboolfoo(Tobj){if(typeid(T)==typeid(obj))returnfalse;returntrue;//您必须以返回true的方式调用(仅在上面提到的)foo()。条件是,无法编辑或重载foo()或typeid不允许针对特定平台进行黑客攻击不允许#define 最佳答案 #includestructB{virtual~B(){}};intmain(){struct:B{}x;assert(foo(x));}行动是overthere.

解决:xxx has been compiled by a more recent version of the Java Runtime (class file version 55.0)

原因当前类是由jdk1.8版本编译,当前运行环境低于jdk1.8,故出现当前情况。javacode和name对应关系49=Java550=Java651=Java752=Java853=Java954=Java1055=Java1156=Java1257=Java1358=Java14解决方案升级当前项目jdk版本号,或者降低引用库编译的jdk版本号android{ ...compileOptions{sourceCompatibilityJavaVersion.VERSION_1_8targetCompatibilityJavaVersion.VERSION_1_8}}