草庐IT

cset_members

全部标签

c++ - 成员初始化列表 : initialize two members from a function returning a tuple

memberinitializerlist中的多个成员是否可以从函数获得的元组中初始化?随着通过元组返回多个值变得越来越流行,我希望有一个解决方案。除了语言限制,我看不出有什么其他原因无法做到这一点。这是我所拥有的mcve:autonew_foo(std::size_tsize)->std::tuple,int*>{autobuffer=std::make_unique(size*sizeof(int)+8);autobegin=static_cast(static_cast(buffer.get()+4));returnstd::make_tuple(std::move(buffer

c++ - 'struct std::pair<int, int >' has no member named ' 序列化'

我正在尝试将序列化集成到我的代码中。但是,我收到“没有命名的成员”错误。我正在阅读的书说std::pair不需要包含头文件并且不存在。如何修复此错误?我的代码如下所示:#include//ofstream/ifstream#include#include#include//stringstream#include//#include#include//#includeusingnamespacestd;intmain(){complexc(1,0);bitsetb(BOOST_BINARY(101));pairp(1,2);strings;std::stringstreamss(s);

c++ - 在 Mac 上安装 xgboost 失败 - ar : no archive members specified

我正在尝试在Mac上安装xgboost。我按照github上的说明进行操作,但是当我运行make-j4时出现错误:c++-std=c++0x-Wall-O3-msse2-Wno-unknown-pragmas-funroll-loops-Iinclude-Idmlc-core/include-Irabit/include-fPIC-DDISABLE_OPENMP-oxgboostbuild/cli_main.obuild/learner.obuild/logging.obuild/c_api/c_api.obuild/c_api/c_api_error.obuild/common/co

c++ - 类型特征 : Check if reference member variable is static or not

我想检查一个类的成员变量是否是静态的。使用std::is_member_pointer适用于除引用成员之外的所有类型。#includestructA{intfoo;};structB:A{};structC{staticintfoo;};structD:C{};structE{int&foo;};structF{staticint&foo;};static_assert(std::is_member_pointer::value,"No");static_assert(std::is_member_pointer::value,"No");static_assert(!std::is_

c++ - “Default member initializer needed within definition of enclosing class outside of member functions” - 我的代码格式不正确吗?

structfoo{structbar{~bar(){}//noerrorw/othisline};bar*data=nullptr;//noerrorw/othislinefoo()noexcept=default;//noerrorw/othisline};是的,我知道,还有一个题目完全相同,但有点不同的问题(涉及noexceptoperator和没有嵌套类型)。那里建议的解决方案(将foo的构造函数替换为foo()noexcept{})改变了语义,这里没有必要:这里我们有一个更好的答案(因此问题不是重复的)。编译器:AppleLLVM版本9.0.0(clang-900.0.37)

C++ 模板 : conditionally enabled member function

我正在创建一个非常小的C++项目,我想创建一个简单的vector类来满足我自己的需要。std::vector模板类不会做。当vector类由char组成时s(即vector),我希望它能够与std::string进行比较.经过一番折腾之后,我编写了既能编译又能执行我想要的操作的代码。见下文:#include#include#includetemplateclassWorkingSimpleVector{public:constElementType*elements_;size_tcount_;//...templateinlinetypenamestd::enable_if::val

c++ - 使用 bind2nd() : "member function already defined or declared" instead of "reference to reference" 的奇怪编译器错误

我最近花了很多时间来理解在这段代码中调用func()时的错误消息:intmain(){vector>v;doublesum=0;for_each(v.begin(),v.end(),bind2nd(ptr_fun(func),&sum));return0;}当func()像这样声明时,代码编译正常:voidfunc(vectorv,double*sum){}当我使用这个声明(为了提高效率)时,我得到了一个编译器错误:voidfunc(constvector&v,double*sum){}我期望看到的错误类似于reference-to-reference错误,因为binder2nd的op

C++ 错误 : Member declaration not found

我是一个C++新手。今天遇到一个问题:在头文件中,我定义了一个类:templateclassPtr_to_const{private:Array_Data*ap;unsignedsub;public:...Ptr_to_const&operator=(constPtr_to_const&p);};在源文件中,我编程为:templatePtr_to_const&Ptr_to_const::operator=(constPtr_to_const&p){...return*this;}编译时,编译器总是说:'找不到成员声明'。为什么?我使用eclipseCDT+CygwinGCC非常感谢!

c++ - Clang claims that `member reference base type ' X' is not a structure or union`,但 X 是具有推导参数的结构模板

考虑以下代码:templatestructX{X(T){}voidfoo(){}};templatestructY{intobject=0;voidbar(){X(object).foo();}};Liveongcc.godbold.orgGCC8.2编译它,而Clang7吐出以下错误::13:18:error:memberreferencebasetype'X'isnotastructureorunionX(object).foo();~~~~~~~~~^~~~这对我来说像是一个错误。条件非常具体:如果任一结构不是模板,或者object不是成员变量,或者不涉及CTAD(类模板参数推导

c++ - "Member is private"虽然我不从外部访问它,但在使用尾随返回类型时

如何解决以下问题?我正在编写一些函数库,它定义了以下与这个问题相关的函数:call(f,arg):调用带有参数的函数。只是我在某些情况下需要的包装器。comp(f1,f2):返回两个函数的组合。返回表示两个函数组合的辅助仿函数。实现如下所示(简化版本仍能说明问题)://Callfwithoneargumenttemplateautocall(constFn&f,constArg&arg)->decltype(f(arg)){returnf(arg);}//HelperfunctorforthefunctionbelowtemplateclassCompFn{Fn1a;Fn2b;publ