草庐IT

first_valid_index

全部标签

c++ - 带有 C++ 的 Lua 脚本 : attempt to index global 'io' (a nil value)

我打算使用luafoAI编写一个程序,所以我试图让它一起工作。但是当我尝试从我的cpp文件加载lua脚本时,我收到了这个错误消息:--toto.lua:1:attempttoindexglobal'io'(anilvalue)这是我的lua脚本:io.write("运行中",_VERSION,"\n")这是我的cpp文件:voidreport_errors(lua_State*L,intstatus){if(status!=0){std::cerr非常感谢。 最佳答案 你不应该直接调用luaopen_*函数。使用luaL_openl

c++ - 如何在不删除元素并将其重新插入到 boost::multi_index_container 的情况下移动元素?

我正在使用boost::multi_index_container提供对元素集合的随机访问和基于散列的访问。我想更改元素的随机访问索引,而不更改基于哈希的索引。这是一段代码:#include#include#include#include#includeusingnamespacestd;usingnamespaceboost;usingnamespaceboost::multi_index;//classrepresentingmyelementsclassElement{public:Element(conststring&new_key):key(new_key){}string

c++ - "Value Validation in Getter/Setter"是好的样式吗?

我的Getter/Setter方法会在设置/返回值之前检查该值。当值无效时,它们会抛出异常(BadArgumentException或IllegalStateException)。这是必需的,因为我们使用无效值初始化所有成员-因此我们避免使用这些无效值(==在其他地方出现错误/段错误/异常)。好处是:当您从模型中收到成员值时,您就知道它们是有效的有效性检查仅在模型对象中执行取值范围在模型对象中定义这似乎很不寻常,因为大多数新团队成员首先提示它-即使在我向他们解释后他们同意我的看法。问题:这是一种好的编程风格吗?(虽然浪费了一点性能)示例代码:inlineboolMyClass::Has

c++ - Boost find_first 它是如何工作的?/定义一个范围

我有一个缓冲区(例如charbuffer[1024]),其中填充了一些数据。现在我想在这个缓冲区中搜索一个子字符串。因为它应该是一个不区分大小写的搜索,所以我正在使用boost::algorithm::ifind_first。所以我这样调用这个函数:boost::iterator_rangebuf_iterator;buf_iterator=boost::algorithm::ifind_first(buffer,"substring");这实际上工作正常。但我担心的是:我只向函数传递了一个charpointer,所以ifind_first应该不知道我的缓冲区在哪里结束,但它仍然有效。

c++ - boost::transform_iterator 不适用于 std::bind( &Pair::first, _1 )?

通过std::map的键集进行迭代的传统任务将我引向了另一个似乎尚未在此处讨论的困惑局面。简而言之,这段代码无法编译(大量使用C++11):typedefstd::pairPair;vectorv{Pair(1,2),Pair(2,3)};usingnamespacestd::placeholders;autochoose_first=std::bind(&Pair::first,_1);boost::make_transform_iterator(v.begin(),choose_first);错误信息如下。notypenamed'result_type'in'structstd::

c++ - 为什么在核心转储中得到 "first/second chance not available"

我使用windbg调试故障转储,在windbg的以下输出中,您可以看到“first/secondchancenotavailable”,为什么first/secondchance不可用?这是什么意思?Thisdumpfilehasanexceptionofintereststoredinit.Thestoredexceptioninformationcanbeaccessedvia.ecxr.(e38.2270):Accessviolation-codec0000005(first/secondchancenotavailable) 最佳答案

c++ - 模板参数列表中的额外 typename 关键字 : is it valid or not?

以下代码使用clang3.5.0和g++4.9.0成功编译(使用-Wall-Wextra-pedantic-errors标志)在C++03(flag-std=C++03)下,C++11(flag-std=C++11),和C++14(flag-std=C++14):namespaceN{typedefintT;enumE{};}templatestructST{};templatestructSE{};intmain(){}在非类型模板参数声明之前添加额外的typename关键字是否有效?请注意,以下代码无法编译(如C++03、C++11和C++14代码):typedefintT;enu

c++ - 使用 boost multi_index_container 来保留插入顺序

我最初开始使用std::multimap来存储许多具有相同键的值,但后来我发现它不会保留具有相同键的值之间的插入顺序。Thisanswer声称可以使用boost::multi_index::multi_index_container来完成,但没有给出示例。查看文档,没有这种用法的示例,而且我无法弄清楚你应该如何使用这个东西。我已经开始期待较少使用的boost库提供糟糕的文档,但这很重要。任何人都可以向我指出一个教程或示例,说明它以我想要的方式使用,或者甚至可以自己提供一个示例吗? 最佳答案 您可以通过将boost::multi_in

c++ - 初级 C++ : Transforming index-syntax into iterator-syntax

我正在尝试学习具有一点Java背景的C++,并且我正在尝试编写返回两个列表的交集的代码。我相信我在概念上有正确的想法,但在语法方面遇到了问题,因为没有任何东西正在编译。这是我想出的代码:#includeusingnamespacestd;#includetemplatelistintersection(constlist&L1,constlist&L2){std::listresult;intpos1=0;intpos2=0;while(pos1L1[pos2]){pos1++;}elseif(L2[pos2]>L1[pos1]){pos2++;}else{result.push_ba

C++ : using index as template parameter in for loop

给定以下模板和特化enumCountryName{Armenia=0,Georgia,Size=2};templateclassCountryInfo;templateclassCountryInfo{/*CODEHERE*/};templateclassCountryInfo{/*CODEHERE*/};我想遍历枚举并为每个特化创建对象。main(){for(autoi=0;i(i))>();}}我收到以下错误:错误:“i”的值在常量表达式中不可用国家信息(); 最佳答案 您想要的是将运行时变量转换为编译时变量(这是模板参数的要求