草庐IT

Type_Ary

全部标签

c++ - 为什么 myClassObj++++ 不会产生编译错误 : '++' needs l-value just as buildin type do?

为什么myint++++使用VS2008编译器和gcc3.42编译器编译得很好??我期待编译器说需要左值,示例见下文。structMyInt{MyInt(inti):m_i(i){}MyInt&operator++()//returnreference,returnalvalue{m_i+=1;return*this;}//operator++needit'soperandtobeamodifiablelvalueMyIntoperator++(int)//returnacopy,returnarvalue{MyInttem(*this);++(*this);returntem;}in

c++ - "Unresolved overloaded function type"尝试将 for_each 与 C++ 中的迭代器和函数一起使用时

//for(unsignedinti=0;i我正在尝试使用for_each循环代替for循环进行赋值。我不确定为什么会收到此错误消息:Infunctionâvoidclean_entry(conststd::string&,std::string&)â:prog4.cc:62:40:error:nomatchingfunctionforcalltoâfor_each(std::basic_string::iterator,std::basic_string::iterator,)â 最佳答案 写:for_each(c.begin()

c++ - 如何修复错误 : unknown type name ‘namespace’

#ifndefUNO_ACTION_#defineUNO_ACTION_namespaceUno{namespaceGame{classGame;}}//namespacenamespaceUno{namespaceAction{using::Uno::Game::Game;classAction{public:virtualboolisDisposeable()=0;virtualvoidtakeAction(Game*game)=0;virtual~Action(){}};}}#endif我在ubuntu12.04上编译这些代码,它返回错误集:action.h:4:1:error:

c++ - 错误 : invalid initialization of non-const reference of type ‘bool&’ from an rvalue of type ‘std::vector<bool>::reference {aka std::_Bit_reference}’

为什么我会收到错误:从类型为“std::vector::reference{akastd::_Bit_reference}”的右值对类型为“bool&”的非常量引用进行无效初始化?vector>vis;bool&visited(intx,inty){returnvis[x][y];//error}据我所知,vector中的operator[]返回引用,所以它应该是一个左值,但它不起作用。我应该怎么做才能让它发挥作用? 最佳答案 那是因为std::vector不是它看起来的样子。std::vector有一个特化与类型bool-它是空间

c++ - 我什么时候应该使用 vector<int>::size_type 而不是 size_t?

在thisquestion我看到以下内容:for(vector::size_typeix=0;ix!=ivec.size();++ix){ivec[ix]=0;}我明白为什么int这里没有使用,但为什么不直接使用size_t?什么情况下应该用vector::size_type而不是size_t? 最佳答案 初级使用时间size_type在模板中。虽然std::vector::size_type通常是size_t,some_other_container::size_type可能是其他类型1。允许用户添加到std的少数内容之一命名空间

Kotlin,针对 Java 互操作 : Idiomatic type for lazy collection?

当面向Java互操作时,惰性集合应该使用什么类型?Sequence对Kotlin调用者最有意义,因为它的扩展函数默认是惰性的,但强制Java调用者处理Kotlin标准库类型并手动转换序列迭代器(序列不扩展可迭代!)Iterable由于for循环中的隐式使用,对Java调用者来说是有意义的,但会导致毫无戒心的Kotlin调用者由于非惰性扩展函数而意外放弃惰性Stream最适合Java和Kotlin调用者,但可能有开销,并且是Java8+(Kotlin目标6+) 最佳答案 您可以通过实现所有这三个来让每个人都开心。例如:dataclas

Kotlin,针对 Java 互操作 : Idiomatic type for lazy collection?

当面向Java互操作时,惰性集合应该使用什么类型?Sequence对Kotlin调用者最有意义,因为它的扩展函数默认是惰性的,但强制Java调用者处理Kotlin标准库类型并手动转换序列迭代器(序列不扩展可迭代!)Iterable由于for循环中的隐式使用,对Java调用者来说是有意义的,但会导致毫无戒心的Kotlin调用者由于非惰性扩展函数而意外放弃惰性Stream最适合Java和Kotlin调用者,但可能有开销,并且是Java8+(Kotlin目标6+) 最佳答案 您可以通过实现所有这三个来让每个人都开心。例如:dataclas

c++ - 为什么 std::result_of<int(int)>::type 无效?

我已阅读以下相关问题:std::result_ofsimplefunctiondecltype,result_of,ortypeof?和thepageonstd::result_ofatcppreference.com.所有这些似乎都表明我应该能够使用:std::result_of::typev1=10;但是,当我尝试使用g++4.9.2构建以下程序时#includeintfoo(){return0;}intmain(){std::result_of::typev1=10;//LINEAstd::result_of::typev2=20;//LINEBreturn0;}我收到“LINE

c++ - C++11 <type_traits> 模板参数类型推导失败

我正在尝试了解如何使用C++(11).这是我的简单测试程序#includetemplateinlineUadd(typenamestd::enable_if::value,U>::typea,typenamestd::enable_if::value,S>::typeb){returna+b;}intmain(intargc,constchar*argv[],constchar*envp[]){unsignedintui;inti;autoa=add(ui,i);return0;}当使用GCC4.8.1编译时,它会出错/home/per/f.cpp:Infunction‘intmain

c++ - 为什么 type_traits 是用专门的模板结构而不是 constexpr 实现的?

标准将它们指定为模板struct而不是简单的bool值constexpr有什么原因吗?在一个可能会在主要问题的良好答案中得到回答的附加问题中,如何对非结构版本执行enable_if操作? 最佳答案 一个原因是constexpr函数无法提供嵌套的type成员,这在某些元编程情况下很有用。为了清楚起见,我不是只谈论产生类型但显然不能产生类型的转换特征(如make_unsigned)constexpr功能。所有类型特征都提供了这样一个嵌套的type成员,甚至是一元类型特征和二进制类型特征。例如is_void::type是false_typ