草庐IT

forward-declaration

全部标签

c++ - 为什么 C++11/14 中的 std::forward 没有 std::move_if_noexcept 对应项?

我观看了ScottMeyers在GoingNative2013“AnEffectiveC++11/14Sampler”上的演讲,他解释了std::move_if_noexcept的使用。所以我认为应该有一个std::forward_if_noexcept来保证forward的异常安全?为什么标准库中没有这样的东西?有没有其他保证的可能? 最佳答案 前向语义已经是有条件的,即它们保留其参数的值类别。另一方面,移动无条件地将其参数的值类别(从左值变为右值)更改为右值(引用),std::move_if_noexcept获得基于移动构造函数

c++11:std::forward 的微妙之处:身份真的有必要吗?

我设置了一个测试用例来学习完美转发。std::stringinner(conststd::string&str){return"conststd::string&";}std::stringinner(std::string&str){return"std::string&";}std::stringinner(conststd::string&&str){return"conststd::string&&";}std::stringinner(std::string&&str){return"std::string&&";}templatevoidouter(T&&t){std::c

C++ "std::string has not been declared"错误

我一直在网站上寻找答案,但找不到任何对我有帮助的答案。当我尝试(如建议的那样)添加这些行时,我有一个使用字符串的代码:usingnamespacestd;usingstd::string;#include我尝试单独使用它们中的每一个,然后将它们一起尝试。最好的情况是所有字符串错误都消失了,但我在“使用std::string”这一行出现了另一个奇怪的错误,错误是:std::string尚未声明。有任何想法吗?谢谢大家。 最佳答案 把#include首先。避免usingheader中的语句,因为您可能会将各种东西带入许多编译单元。usi

c++ - std::forward 如何接收正确的参数?

考虑:voidg(int&);voidg(int&&);templatevoidf(T&&x){g(std::forward(x));}intmain(){f(10);}既然id-expressionx是一个左值,而std::forward有左值和右值的重载,为什么调用不绑定(bind)到重载std::forward接受左值?templateconstexprT&&forward(std::remove_reference_t&t)noexcept; 最佳答案 它确实绑定(bind)到采用左值的std::forward的重载:tem

c++ - 如何删除 VS 警告 C4091 : 'typedef ' : ignored on left of 'SPREADSHEET' when no variable is declared

此警告在我的代码中由同一个声明多次触发,内容如下://SpreadsheetstructuretypedefstructSPREADSHEET{intID;//IDofthespreadsheetUINTnLines;//NumberoflinesvoidCopyFrom(constSPREADSHEET*src){ID=src->ID;nLines=src->nLines;}};我不想只是关闭该警告,而是更改代码,以免出现警告!注意:我不想在这里声明任何变量(它是一个头文件),只定义结构'SPREADSHEET'应该包含的内容... 最佳答案

c++ - 在标准中,什么是 "derived-declarator-type"?

在C++(C++11)标准的不同地方,声明是根据derived-declarator-type-list来描述的。我正在研究右值引用,在这种情况下使用这个术语是至关重要的(第8.3.2节):InadeclarationTDwhereDhaseitheroftheforms    &attribute-specifier-seqoptD1    &&attribute-specifier-seqoptD1andthetypeoftheidentifierinthedeclarationTD1is“derived-declarator-type-listT,”thenthetypeofth

C++ 错误 : ‘string’ has not been declared

在我的头文件中,我得到了error:‘string’hasnotbeendeclared错误,但在文件顶部我有#include,那么我怎么会得到这个错误呢? 最佳答案 string位于std命名空间中,您必须使用std::string或通过using指令或using将其引入范围声明。 关于C++错误:‘string’hasnotbeendeclared,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/

c++ - 对依赖基类成员的非限定访问导致 "A declaration of [x] must be available"

代码://test3.cpp#includeusingnamespacestd;templatestructptr_stack_tp;templatestructptr_stack_tp:publicstack{~ptr_stack_tp(){while(!empty()){operatordelete(top());pop();}}};intmain(){}错误信息(gcc4.7.2):test3.cpp:Indestructor'ptr_stack_tp::~ptr_stack_tp()':test3.cpp:15:23:error:therearenoargumentsto'em

c++ - C 中 'allocated object having no declared type' 的 C++ 等价物是什么?

我正在用C++为我的VM编写内存管理器。好吧,更准确地说,VM指令将使用嵌入式内存管理器编译成C++。我在处理C方面更加自如,但现在我确实需要对异常处理的原生支持,这几乎是我使用C++的唯一原因。C和C++都有严格的别名规则,即不兼容类型的两个对象不得重叠,C中的union有一个小异常(exception)。但要定义malloc、calloc、alloca等内存分配函数的行为,C标准有以下段落。6.5-6Theeffectivetypeofanobjectforanaccesstoitsstoredvalueisthedeclaredtypeoftheobject,ifany.Allo

c++0x : resolving ambiguity between function-definition followed by empty-declaration and simple-declaration

我在思考c++0x规范中明显的歧义时遇到了问题,另请参阅:http://www.nongnu.org/hcb/假设我们有代码voidfoo(){};我个人将代码解释为function-definition后跟empty-declaration。但是,看看语法规范,我想说这可以很容易地解释为simple-declaration,它是block-declaration的一部分,因此被提及declaration列表中的较早...这是我对如何将其解析为简单声明的解释:voidfoo(){};"->简单声明void->decl-specifier-seq->decl-specifier->typ