草庐IT

has-scope

全部标签

c++ - 在 vs2008 SP1 中禁用检查迭代器时出现问题 (_HAS_ITERATOR_DEBUGGING=0)

当我尝试禁用已检查的迭代器时,在Debug模式下运行vs2008SP1时遇到了一些问题。以下程序重现了该问题(字符串析构函数崩溃):#define_HAS_ITERATOR_DEBUGGING0#includeintdo_stuff(std::stringconst&text){std::string::const_iteratori(text.end());return0;}intmain(){std::ostringstreamos;os我找到了similarpost在gamdev.net上讨论了在vs2005中遇到这个问题。该帖子中的示例程序在2008SP1上按原样为我编译-但是

c++ - 使用自定义删除器 boost scoped_ptr/scoped_array

我不知道如何让scoped_ptr或scoped_array使用自定义删除器。也许还有另一种实现类似于shared_ptr允许受控删除?顺便说一句,为什么shared_ptr允许自定义删除器而scoped_ptr不允许?只是好奇。 最佳答案 Idon'tseehowtogetscoped_ptrorscoped_arraytousecustomdeleter你不能。Maybethereisanotherimplementationwhichallowscontrolleddeletionsimilartoshared_ptr?如果您

C++:引用 "out of scope"对象

关于引用文献,有一件事我一直不明白,我希望有人能帮助我。据我所知,引用不能为空。但是如果你有一个函数foo()返回对堆栈对象的引用会发生什么:Object&foo(){Objecto;returno;}Object&ref=foo();理论上ref将引用一个不存在的对象,因为一旦函数返回,o就会超出范围。这里发生了什么? 最佳答案 这会导致未定义的行为。不要这样做。在实现方面,实际上,引用将指向调用foo的堆栈框架所在的堆栈。在许多情况下,该内存仍然有意义,因此错误通常不会立即显现出来。因此,您应该注意永远不要创建这样的悬空引用。

c++ - "Nested"scoped_lock

我缩短的简化类如下所示:classA{public://...methodA();methodB();protected:mutableboost::mutexm_mutex;sometype*m_myVar;}A::methodA(intsomeParam){boost::mutex::scoped_lockmyLock(m_mutex);m_myVar->doSomethingElse();}A::methodB(intsomeParam){boost::mutex::scoped_lockmyLock(m_mutex);m_myVar->doSomething();this->m

c++ - 'struct std::pair<int, int >' has no member named ' 序列化'

我正在尝试将序列化集成到我的代码中。但是,我收到“没有命名的成员”错误。我正在阅读的书说std::pair不需要包含头文件并且不存在。如何修复此错误?我的代码如下所示:#include//ofstream/ifstream#include#include#include//stringstream#include//#include#include//#includeusingnamespacestd;intmain(){complexc(1,0);bitsetb(BOOST_BINARY(101));pairp(1,2);strings;std::stringstreamss(s);

c++ - 如何使用 std::scoped_allocator_adapter?

据我了解,std::scoped_allocator_adapter提供一种控制机制,用于指定单独哪个分配器将由容器、其元素、其元素的元素等使用,假设元素本身是容器。也就是说,我无法理解std::scoped_allocator_adapter的语义.BjarneStroustrup在TheC++ProgrammingLanguage,section34.4.4,pg中提供了以下4个示例。1001(在接下来的问题中,我将它们称为Example-1、Example-2等。):Wehavefouralternativesforallocationofvectorsofstrings://v

C++ block scope extern declaration linkage,混淆C++标准解释

标准N3242(C++11草案)和N3797(C++14draft)两者有相同的段落。§3.5Programandlinkage[basic.link]¶6Thenameofafunctiondeclaredinblockscopeandthenameofavariabledeclaredbyablockscopeexterndeclarationhavelinkage.Ifthereisavisibledeclarationofanentitywithlinkagehavingthesamenameandtype,ignoringentitiesdeclaredoutsidethei

c++ - 使用以下 has_member 函数时 SFINAE 无法正常工作的原因是什么?

我正在尝试来自WalterBrown'sTMPtalk的示例我正试图让他的has_member实现正常工作。然而,该实现似乎错误地返回true,这让我相信我不理解SFINAE的一些细节。#include#includetemplateusingvoid_t=void;templatestructhas_type_member:std::false_type{};templatestructhas_type_member>:std::true_type{};structFooWithType{typedefinttype;};structFooNoType{};intmain(){std

c++ - 错误 : uint64_t was not declared in this scope when compiling C++ program

我正在尝试一个简单的程序来打印steady_clock的时间戳值,如下所示:#include#includeusingnamespacestd;intmain(){cout(steady_clock::now().time_since_epoch()).count();cout但是每当我像这样编译时g++-oabcabc.cpp,我总是会遇到错误:Infileincludedfrom/usr/include/c++/4.6/chrono:35:0,fromabc.cpp:2:/usr/include/c++/4.6/bits/c++0x_warning.h:32:2:error:#er

c++ - 非本地 lambda 和捕获变量 - "block scope"是什么意思

我目前正在玩c++11lambda,发现了一个我无法理解的例子。根据标准:Alambda-expressionwhosesmallestenclosingscopeisablockscope(3.3.3)isalocallambdaexpression;anyotherlambda-expressionshallnothaveacapture-listinitslambda-introducer所以,我创建了一个简单的例子:inta=10;autox=[a]{return1;};intmain(){intk=5;autop=[k]{returnk;};return0;}ideone中的