草庐IT

make_member_delegate

全部标签

c++ - Visual Studio 2015 “non-standard syntax; use ' &' to create a pointer to member”

我正在学习C++并尝试制作一个小游戏井字游戏。但我不断得到C3867,非标准语法;使用'&'创建一个要记住的指针。这是我的井字游戏.h:#pragmaonce#includeusingnamespacestd;classTicTacToe{public:TicTacToe();stringgetName1();stringgetName2();voidprintBoard();voidclearBoard();voidsetName1(stringplayer1Name);voidsetName2(stringplayer2Name);voidsetSign1(stringplayer

c++ - 在 std::make_shared 中使用 c++ 聚合初始化

根据我的理解,以下代码构造了一个Foo类型的对象,然后将该对象移动到std::make_shared分配的内存中structFoo{std::strings;inti;charc;};intmain(intargc,char*argv[]){autofoo=std::make_shared(Foo{"hello",5,'c'});}有没有可能aggregateinitializeFoo直接放入std::make_shared分配的内存? 最佳答案 您可以使用可变参数构造函数模板创建一个适配器来转发参数,例如:templatestru

c++ - 在 std::make_shared 中使用 c++ 聚合初始化

根据我的理解,以下代码构造了一个Foo类型的对象,然后将该对象移动到std::make_shared分配的内存中structFoo{std::strings;inti;charc;};intmain(intargc,char*argv[]){autofoo=std::make_shared(Foo{"hello",5,'c'});}有没有可能aggregateinitializeFoo直接放入std::make_shared分配的内存? 最佳答案 您可以使用可变参数构造函数模板创建一个适配器来转发参数,例如:templatestru

c++ - std::make_shared() 是否使用自定义分配器?

考虑thiscode:#include#includeclassSomeClass{public:SomeClass(){std::coutptr1(newSomeClass);std::coutptr2(std::make_shared());std::cout这是它的输出:CustomnewSomeClass()Anotherone...SomeClass()Done!~SomeClass()~SomeClass()Customdelete显然,std::make_shared()没有调用new运算符——它使用的是自定义分配器。这是std::make_shared()的标准行为吗?

c++ - std::make_shared() 是否使用自定义分配器?

考虑thiscode:#include#includeclassSomeClass{public:SomeClass(){std::coutptr1(newSomeClass);std::coutptr2(std::make_shared());std::cout这是它的输出:CustomnewSomeClass()Anotherone...SomeClass()Done!~SomeClass()~SomeClass()Customdelete显然,std::make_shared()没有调用new运算符——它使用的是自定义分配器。这是std::make_shared()的标准行为吗?

c++ - "cannot access private member' "只有当类有导出链接时才会出错

我最近不得不更改几个类的链接规范并遇到了问题。其中两个类包含一个std::map和一个std::unique_ptr作为值类型。更改链接后,编译器开始提示“无法访问在类'std::unique_ptr'中声明的私有(private)成员”错误。有谁知道为什么只有在提供导出规范或有解决方案时才会发生这种情况?示例代码:#includestructSomeInterface{virtual~SomeInterface()=0;};//ThisclasscompileswithnoproblemsstructLocalClass{std::map>mData;};//Thisclassfai

c++ - "cannot access private member' "只有当类有导出链接时才会出错

我最近不得不更改几个类的链接规范并遇到了问题。其中两个类包含一个std::map和一个std::unique_ptr作为值类型。更改链接后,编译器开始提示“无法访问在类'std::unique_ptr'中声明的私有(private)成员”错误。有谁知道为什么只有在提供导出规范或有解决方案时才会发生这种情况?示例代码:#includestructSomeInterface{virtual~SomeInterface()=0;};//ThisclasscompileswithnoproblemsstructLocalClass{std::map>mData;};//Thisclassfai

c++ - 为什么 make_optional 会衰减它的参数类型?

(可能不是C++14,可能是LibraryTS)工具make_optional被定义(inn3672)为:templateconstexproptional::type>make_optional(T&&v){returnoptional::type>(std::forward(v));}为什么要转换类型T(即不只是返回optional),并且是否有使用decay的哲学(以及实际)理由具体作为转型? 最佳答案 decay的一般用途就是取一个类型,修改为适合存储。看看这些decay的例子工作,而remove_reference不会:a

c++ - 为什么 make_optional 会衰减它的参数类型?

(可能不是C++14,可能是LibraryTS)工具make_optional被定义(inn3672)为:templateconstexproptional::type>make_optional(T&&v){returnoptional::type>(std::forward(v));}为什么要转换类型T(即不只是返回optional),并且是否有使用decay的哲学(以及实际)理由具体作为转型? 最佳答案 decay的一般用途就是取一个类型,修改为适合存储。看看这些decay的例子工作,而remove_reference不会:a

c++ - C++ 中的命名冲突 : How to access a struct member called "class"

我在使用xlib库时遇到了一个命名问题:我正在使用一个结构,它有一个名为“类”的成员。我假设这个库主要用于纯C程序。所以没有问题。但我正在用C++编程,这里的名称“类”是一个关键字,不能用来表示变量。所以,如果我通过访问结构myvariable=mystruct->class;我收到了错误:“class”之前的预期unqualified-id鉴于我无法更改结构本身,尽管存在命名冲突,我如何访问该结构成员? 最佳答案 GiventhatIcannotchangethestructitself,howcanIaccessthisstru