草庐IT

namespace-scoped

全部标签

c++ - 当内部范围不起作用时,为什么编译器不采用 namespace 名称?

我认为我非常了解名称查找(在观看了几个有关它的视频并阅读了大量内容之后)但我只是遇到了这种情况:#includenamespacetest{structId{};voiddo_something(constId&){std::cout尖线不编译(在GCC4.8和VC11U2上)因为它试图使用成员函数test::Test::do_something()而不是命名空间作用域的test::do_something(constId&)这似乎是唯一可能的候选对象。显然,成员函数名称隐藏了命名空间范围内的名称,这让我感到惊讶,因为我记得在其他上下文中使用了几乎相似的代码而没有产生这个问题(但最终情

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++ - 氧气/C++ : how to link to anonymous namespace variables

我正在使用Doxygen来记录我的代码。许多代码在定义常量的cpp文件中都有匿名namespace。我已经设置:EXTRACT_ANON_NSPACES=YES在我的Doxygen文件中,所有匿名命名空间都按需要进行了记录。我的问题是我想引用匿名命名空间中的变量。例如,假设其中一个命名空间在我的Doxygen文档中定义在MyClass::anonymous_namespace{MyFile.cpp}::kMyConstant下。我认为另一个注释block(例如,一个函数)可以链接到该常量,例如:@seeMyClass::anonymous_namespace{MyFile.cpp}::

c++ - boost 是否使用 C++11 "inline namespaces"来避免运行时出现 ABI 不兼容错误?

C++11具有称为“内联命名空间”的功能,它允许作者在链接时强制执行ABI兼容性,而无需篡改API。例如,来自@HowardHinnant的这些有用的答案解释了libc++如何使用内联命名空间:Usinglibstdc++compiledlibrarieswithclang++-stdlib=libc++Whycan'tclangwithlibc++inc++0xmodelinkthisboost::program_optionsexample?我的问题是:boost是否利用了这个C++11特性?看起来一些boost开发者至少是thinking最终一次使用它。但是那个线程很旧。它曾经发

c++ - 声明 `using namespace C;` 对于证明 [namespace.udir]/3 中示例中显示的结果至关重要

据我所知,usingnamespaceC;下面在namespaceD中的声明对于编译器提示歧义是必要的qualified-idsB::C::i和A::i在下面的代码中,这是一个例子[namespace.udir]/3中的C++标准:namespaceA{inti;namespaceB{namespaceC{inti;}usingnamespaceA::B::C;voidf1(){i=5;//OK,C​::​ivisibleinBandhidesA​::​i}}namespaceD{usingnamespaceB;//usingnamespaceC;voidf2(){i=5;//ambi

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

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

c++ - 全局范围内的匿名 namespace 内的名称可以有前导下划线吗?

根据规范,不允许使用前导下划线的全局名称:17.4.3.1.2Globalnames—Eachnamethatbeginswithanunderscoreisreservedtotheimplementationforuseasanameintheglobalnamespace.这是否也适用于在顶级匿名命名空间中定义的名称? 最佳答案 以前导下划线开头,后跟非大写字母数字字符且不包括双下划线的名称仅在全局命名空间中保留。这样做的原因是在某些系统上某些名称需要有一个前导下划线或者已经被底层操作系统和/或其C库使用。匿名命名空间中的名称

c++ - 为什么类型特征不适用于 namespace 范围内的类型?

我正在为我的C++序列化库设计类型注册功能。但是我遇到了一个关于类型特征的奇怪问题。我正在使用VisualStudio2017和/std:c++latest。#includeintreg(...);templateconstexprboolis_known=!std::is_same_v;//-----fortype1inglobalscope------structtype1{};voidreg(type1*);static_assert(is_known);//success//-----fortype2innamespacescope----namespacens{structt

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