草庐IT

member-initialization

全部标签

C++ - 错误 : 'list' does not name a type (list object as member variable in class)

关闭。这个问题是notreproducibleorwascausedbytypos.它目前不接受答案。这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topic在这里,这个问题的解决方式不太可能帮助future的读者。关闭8年前。Improvethisquestion我经常遇到“'xxx'doesnotnameatype”错误,我之前读过的大多数帖子都提到这个错误是由于一些依赖性问题而发生的。但是,我似乎找不到我的。这是我得到的:GameLib.h#ifndefGAMELIB_H_#defineGAMELIB_H_//Structuresstructplayer

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++ - Goto before variable initialization 导致编译错误

考虑这段代码(VS2008):voidWordManager::formatWords(std::stringconst&document){document_=document;unsignedintcurrentLineNo=1;size_toldEndOfLine=0;size_tendOfLine=document_.find('\n');while(endOfLine!=std::string::npos){std::stringline=document_.substr(oldEndOfLine,(endOfLine-oldEndOfLine));if(line.size(

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++ - 在编译时验证 std::initializer_list 的内容

我试图在编译时确定std::initializer_list中的所有值是否都是唯一的。我能够找到valiatethesize的解决方案的列表,但无法将其应用于内容。我尝试过使用自由函数和构造函数,但这两种方法都导致GCC4.7.2出现以下错误。error:non-constantconditionforstaticassertionerror:'begin'isnotaconstantexpression我意识到std::initializer_list的成员没有被声明为constexpr但我希望有一个像大小验证这样的解决方案。是否可以在编译时使用类似以下内容验证内容?#include

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++ - 使用 C++11 initializer_list 实现类 std::array 容器

std::array唯一和imo非常不方便的警告是它不能像内置C数组一样从初始化列表中推断出它的大小,它的大小必须作为模板传递.是否可以使用C++11initializer_list实现类似std::array的容器(围绕内置C数组的薄包装器)?我问是因为,与std::array不同,它会自动从初始化列表中推导出数组的大小,这要方便得多。例如://il_arrayisthehypotheticalcontainer//automaticallydeducesitssizefromtheinitalizerlistil_arraymyarr={2,4,6,7,8};如果没有提供初始化列表