草庐IT

scope-resolution

全部标签

C++ 标准 : do namespace-scoped constexpr variables have internal linkage?

假设我们有一个标题foo.h包含以下内容:#ifndefFOO_H_#defineFOO_H_namespacefoo{constexprstd::string_viewkSomeString="blah";}#endif//FOO_H_foo::kSomeString是否保证在包含foo.h的任何翻译单元中具有内部链接?这在C++11和C++17之间是否有所不同?在标准草案中[basic.link]/3说Anamehavingnamespacescopehasinternallinkageifitisthenameof[...]anon-inlinevariableofnon-vol

c++ - std::atomic<std::chrono::high_resolution_clock::time_point> 无法编译

我需要std::chrono::high_resolution_clock::time_point我想从一个线程写入并从另一个线程读取的字段。如果我声明它是我的代码编译没有任何错误。但为了让我的字段在另一个线程中可见,我用std::atomic将其包围像这样std::atomic现在我有以下编译错误:/usr/include/c++/4.8/atomic:167:7:error:function‘std::atomic::atomic()[with_Tp=std::chrono::time_point>>]’defaultedonitsfirstdeclarationwithanexc

c++ - 带有 Cygwin 1.7 的 GoogleTest 1.6 编译错误 : 'fileno' was not declared in this scope

带有Cygwin1.7的GoogleTest1.6:“fileno”未在此范围内声明在EclipseCDT中对Factorial()函数进行简单测试时出现错误消息:Invoking:CygwinC++Compilerg++-std=c++0x-DGTEST_OS_CYGWIN=1-I"E:\source\gtest-1.6.0\include"-O0-g3-Wall-c-fmessage-length=0-MMD-MP-MF"src/challenge.d"-MT"src/challenge.d"-o"src/challenge.o""../src/challenge.cpp"Infi

c++ - 为什么 boost 没有 make_scoped()?

Boost的make_shared()函数promise在尝试创建shared_ptr时是异常安全的.为什么没有make_scoped()相等的?是否有通用的最佳做法?这是来自boost::scoped_ptrdocumentation的代码示例这对我来说似乎不安全:boost::scoped_ptrx(newShoe);这行代码会依次完成这三件事:为Shoe分配堆内存调用Shoe的构造函数调用boost::scoped_ptr的构造函数如果Shoe的构造函数抛出异常,内存将被泄露。(参见R.MartinhoFernandes的回答)scoped_ptr不会处理释放,因为它还没有被构造

C++ 错误 : Sleep was not declared in this scope

我在Ubuntu中使用带有codeBlocks的C++,在GCC4.7中boost1.46[yield_k.hpp]我得到这个编译时错误:error:Sleepwasnotdeclaredinthisscope代码:#includeusingnamespacestd;intmain(){cout如何解决此错误?我希望程序挂起1秒。 最佳答案 Sleep是一个Windows函数。对于Unix,请考虑使用nanosleep(POSIX)或usleep(BSD;已弃用)。一个nanosleep示例:voidmy_sleep(unsigne

c++ - 为什么 Alexandrescu 不能使用 std::uncaught_exception() 在 ScopeGuard11 中实现 SCOPE_FAIL?

这个问题在这里已经有了答案:Scope(failure)inC++11?(2个回答)关闭9年前。毫无疑问,很多人都熟悉Alexandrescus先生的ScopeGuard模板(现在是Loki的一部分)和这里介绍的新版本ScopeGuard11:http://channel9.msdn.com/Shows/Going+Deep/C-and-Beyond-2012-Andrei-Alexandrescu-Systematic-Error-Handling-in-C这里有来源:https://gist.github.com/KindDragon/4650442在2012年及以后的c++演讲中

c++ - 我在哪里可以为我的 C++ 项目找到一个好的 Scope Guard 实现?

我最近刚刚了解了ScopeGuardC++习语。不幸的是,我找不到任何好的实现。谁能给我指点C++中一些好的和可用的ScopeGuard实现?谢谢,博达·赛多。 最佳答案 原始的ScopeGuard类包含在thisDr.Dobb'sarticle中AndreiAlexandrescu和PetruMarginean。一个稍微改进的版本,与JoshuaLehrer的一些更改可用here.(Lehrer的版本是我在项目中使用的版本。)它也包含在Loki中。图书馆。Boost现在有一个ScopeExit比ScopeGuard更强大的库(因为

c++ - protected 成员是派生类中的 "not declared in this scope"

这个问题在这里已经有了答案:accessingprotectedmembersofsuperclassinC++withtemplates[duplicate](2个回答)关闭8年前。#include#includetemplateclassBase{protected:std::vectordata_;};templateclassDerived:publicBase{public:voidclear(){data_.clear();}};intmain(intargc,char*argv[]){Derivedderived;derived.clear();return0;}我无法编

node.js - 如何将 NPM 包迁移到组织 @scope

NPM最近为模块引入了@scopes/organizations。有没有将现有模块迁移到组织的好方法?是否有任何工具可以为大量包自动化它?NPM是否支持重定向,以便其他软件仍然可以使用旧名称,但会收到应该更新的通知? 最佳答案 您可以从以下位置更改您的package.json:"name":"project-name"到:"name":"@scope/project-name"并发布包:npmpublish--access=public更新:--access=public需要参数才能使作用域包公开-否则默认情况下它将是私有(priv

node.js - 为什么我得到 "Error: Resolution method is overspecified"?

升级后Mocha连简单的测试都跑不了这里是代码constassert=require('assert');it('shouldcompletethistest',function(done){returnnewPromise(function(resolve){assert.ok(true);resolve();}).then(done);});我从here获取此代码我知道它现在抛出异常错误:解决方法被过度指定。指定回调*或*返回一个Promise;不是两者都有。但是如何让它工作呢?我不明白。我有node-v6.9.4mocha-v3.2.0如何以新的正确格式运行这段代码?