草庐IT

default_scope

全部标签

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

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

c++ - 为什么 "default"是复制/移动构造函数或析构函数?

C++0x允许您将某些函数指定为默认函数:structA{A()=default;//defaultctorA(Aconst&)=default;//copyctorA(A&&)=default;//movectorA(Other);//otherctor~A()=default;//dtorA&operator=(Aconst&)=default;//copyassignmentA&operator=(A&&)=default;//moveassignment};这些函数的实现与编译器生成它们一样,在您不声明自己的大多数情况下通常会发生这种情况。如果您声明任何构造函数(上述任何其他构

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++ - 如何使用 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++ - “Default member initializer needed within definition of enclosing class outside of member functions” - 我的代码格式不正确吗?

structfoo{structbar{~bar(){}//noerrorw/othisline};bar*data=nullptr;//noerrorw/othislinefoo()noexcept=default;//noerrorw/othisline};是的,我知道,还有一个题目完全相同,但有点不同的问题(涉及noexceptoperator和没有嵌套类型)。那里建议的解决方案(将foo的构造函数替换为foo()noexcept{})改变了语义,这里没有必要:这里我们有一个更好的答案(因此问题不是重复的)。编译器:AppleLLVM版本9.0.0(clang-900.0.37)

c++ - std::is_default_constructible<T> 错误,如果构造函数是私有(private)的

我有以下片段#include#includeclassC{C(){}};intmain(){static_assert(!boost::has_trivial_default_constructor::value,"Constructible");static_assert(!std::is_default_constructible::value,"Constructible");}条件不相等,但第一个条件工作正常,第二个构造给出错误,构造函数是私有(private)的。编译器gcc4.7...那么,这是gcc错误,还是由标准定义的?http://liveworkspace.org/

C++ [[gnu::visibility ("default")]] 与 Windows 和 Linux 上的 __declspec(dllexport)

我需要用C++创建一些共享库,我使用linux作为我的开发者操作系统。我知道如果我想通过dlsym/LoadLibrary加载它们,我需要让符号可见。所以在Linux中,我所有的符号都遵循这种模式:extern"C"[[gnu::visibility("default")]]voidf();我在启用C++11的情况下使用了clang,并且能够在我的主机程序中加载f。当我转移到Windows时,我使用启用了C++11的GCC4.8.2,并且该模式在Windows机器上也适用于LoadLibrary。(我需要使用C++11来实现新的属性语法)。我知道在Windows上我需要使用__decl

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

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

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