草庐IT

apple_push_notification_options

全部标签

引用类型的 C++11 成员变量, vector push_back 后的不同行为

我正在使用其他人的类,当我将它插入vector时它表现得很奇怪。它涉及一个成员变量,它是对另一个成员变量的引用。这是最小的独立示例:#include#includeclassMyclass{public:Myclass():a(1.0){}floata;float&a_ref=a;voidaddOne(){a=a+1.0;}};intmain(){Myclassinstance1;instance1.addOne();//prints2:std::coutvec;Myclassinstance2;vec.push_back(instance2);vec.at(0).addOne();/

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++ - boost::optional<T&> vs T*

我试图了解何时是使用boost附带的一些结构的合适时间,并且对boost::optional的使用有疑问有引用。假设我有以下类,使用boost::optional:classMyClass{public:MyClass(){}initialise(Helper&helper){this->helper=helper;}boost::optionalgetHelper(){returnhelper;}private:boost::optionalhelper;}我为什么要使用上面的而不是:classMyClass{public:MyClass():helper(nullptr){}ini

c++ - boost::optional<T&> vs T*

我试图了解何时是使用boost附带的一些结构的合适时间,并且对boost::optional的使用有疑问有引用。假设我有以下类,使用boost::optional:classMyClass{public:MyClass(){}initialise(Helper&helper){this->helper=helper;}boost::optionalgetHelper(){returnhelper;}private:boost::optionalhelper;}我为什么要使用上面的而不是:classMyClass{public:MyClass():helper(nullptr){}ini

c++ - 链接时找不到 C++ 库,编译 `boost::program_options` 示例时出错

我正在尝试编译multiple_sources.cpp在我的电脑上编译。我正在运行完全更新的XubuntuLucidLynx。使用g++-cmultiple_sources.cpp可以毫无问题地编译,但是当我尝试使用g++multiple_sources.o链接并制作可执行文件时,我得到:multiple_sources.cpp:(.text+0x3d):undefinedreferenceto`boost::program_options::options_description::m_default_line_length'multiple_sources.cpp:(.text+0

c++ - 链接时找不到 C++ 库,编译 `boost::program_options` 示例时出错

我正在尝试编译multiple_sources.cpp在我的电脑上编译。我正在运行完全更新的XubuntuLucidLynx。使用g++-cmultiple_sources.cpp可以毫无问题地编译,但是当我尝试使用g++multiple_sources.o链接并制作可执行文件时,我得到:multiple_sources.cpp:(.text+0x3d):undefinedreferenceto`boost::program_options::options_description::m_default_line_length'multiple_sources.cpp:(.text+0

c++ - vector::push_back 坚持使用复制构造函数,尽管提供了移动构造函数

我从gcc收到一个奇怪的错误,不知道为什么。我制作了以下示例代码以使问题更加清晰。基本上,定义了一个类,我将其复制构造函数和复制赋值运算符设为私有(private),以防止意外调用它们。#include#includeusingstd::vector;classbranch{public:intth;private:branch(constbranch&other);constbranch&operator=(constbranch&other);public:branch():th(0){}branch(branch&&other){printf("called!other.th=%

c++ - vector::push_back 坚持使用复制构造函数,尽管提供了移动构造函数

我从gcc收到一个奇怪的错误,不知道为什么。我制作了以下示例代码以使问题更加清晰。基本上,定义了一个类,我将其复制构造函数和复制赋值运算符设为私有(private),以防止意外调用它们。#include#includeusingstd::vector;classbranch{public:intth;private:branch(constbranch&other);constbranch&operator=(constbranch&other);public:branch():th(0){}branch(branch&&other){printf("called!other.th=%

c++ - g++/libstdc++中std::optional的实现状态?

由于我正在开发一个将于2014年左右公开发布的C++库,因此我目前需要做出设计选择。将与C++14一起发布的非常有用的工具之一是std::optional。我想知道g++/libstdc++的版本我可以使用-std=c++1y。 最佳答案 更新(2016年10月):std::optional不在最终的C++14标准中,因此它永远不会与-std=c++1y一起使用.相反,GCC4.9包含std::experimental::optional可用-std=c++1y.GCC7将包括std::optional与-std=c++1z即C++