草庐IT

namespace-scoped

全部标签

c++ - 为什么 "#define A"会干扰 "namespace A{}"?

以下代码可以编译:namespaceA{inti;}namespaceB{inti;}intmain(){return0;}但是下面的代码无法编译:#defineA#defineBnamespaceA{inti;}namespaceB{inti;}intmain(){return0;}错误信息是error:redefinitionof'int{anonymous}::i'为什么我定义了A和B之后命名空间的名称变成了匿名的?使用的编译器:gcc-4.9.3。 最佳答案 在#defineA#defineBnamespaceA{inti;

c++ - 'ios' : is not a class or namespace name

我正在尝试使用上述代码将矩阵写入文件。但我收到以下错误:'ios':不是类或命名空间名称。我的代码:std::ofstreammyfile;myfile.open("C:/Users/zenitis/Desktop/bots/Nova/data/ownStatus.txt",ios::out|ios::app);for(inti=0;i对这个问题有什么想法吗?? 最佳答案 ios是std的成员。也就是说,您想使用以下方法之一来引用它:usingnamespacestd;//badusingstd::ios;//slightlybet

c++ - C2039 : Class is not a member of Namespace

Mage/Interface/Context.h#pragmaonce#include#include#include#includenamespaceMage{namespaceInterface{classContext{protected:RenderingContext*ctx;VertexBuffer*vbo;glm::mat4projection;Mage::Interface::Frame*uiParent;public:Context(RenderingContext*ctx);~Context();voidrender();Mage::Interface::Frame

c++ - 错误 C2143 : syntax error : missing ';' before 'namespace'

我是C++和OpenGL的新手,我一直在尝试在场景中显示3D对象。它与一个工作正常,但是当我尝试更改我的代码以添加第二个时,我关于显示相机位置的HUD文本的代码开始出错。显示了上面的错误,它显然在sstream文件(#include)中。我试过四处寻找并寻求帮助,但没有任何帮助/我理解。当我注释掉#include行和使用它的代码时,我得到类似的说法“errorC2143:syntaxerror:missing';'在我的main.cpp文件中“使用”之前。我正在运行VisualStudio2010,我什至尝试关闭并重新打开整个系统,并将代码复制到一个新项目中。将不胜感激。#includ

c++ - 为什么我不能从函数返回 Boost::Scoped_ptr?

所以我尝试围绕boost.extension函数创建一些包装器来创建类。所以我创建了一个函数:templateboost::scoped_ptrget_class(shared_library&lib,std::stringclass_name,ConstructorTypevalue){map>lib_factories=get_factories(lib);returnboost::scoped_ptrlib_class(lib_factories[class_name].create(value));}调用:templatemap>get_factories(shared_lib

c++ - `unique_lock`、 `scoped_lock` 和 `lock_guard` 中指定的 mutex_type 的用例是什么?

用于保护std::mutex的c++11mutexRAII类型都有一个typedef:typedefMutexmutex_type;std::lock_guard::mutex_typestd::unique_lock::mutex_typestd::scoped_lock::mutex_type这个成员typedef有什么意义?起初我认为它可以用来概括创建一个对象来移动锁(在unique_lock的情况下)例如:templatevoidfunction(SomeLockin)SomeLock::mutex_typenewMutex;//Dosomething但我无法想象它的用途。需要

c++ - 有没有办法确保代码只使用来自 std 的名称,而不是全局 namespace ?

当使用格式为的header时,一个实现会将名字放入std命名空间。而且它可能也将名称放入全局命名空间中,如描述的那样here:[ Example:Theheaderassuredlyprovidesitsdeclarationsanddefinitionswithinthenamespacestd.Itmayalsoprovidethesenameswithintheglobalnamespace.[...]— endexample ]是否有(可能依赖于编译器)规避/禁用此行为的方法(我愿意接受任何棘手的解决方案)?我想使用来自std的名字仅,并且我希望在使用来自全局命名空间的名称时出

c++ - 将两个或多个 C++ namespace 合并为一个

首先,对不起我的英语。好的,我正在开发一个执行特定过程的程序。这个过程需要定义一些类和函数。所有这些都必须按block组织才能访问它们。我的第一个想法是使用命名空间(C++),得到这样的东西:namespaceLoadSystem{namespaceParseBlock1{classClassA{...}classClassB{...}classClassC{...}}namespaceParseBlock2{classClassA{...}classClassB{...}classClassC{...}}}所以,我正在阅读以了解这是否好。我已经读到我不能使用很多嵌套命名空间,因此,为

c++ - 在这种特殊情况下,为什么不需要将 std::hash() 的特化注入(inject)到 std namespace 中?

考虑usingnamespacestd;templatestructhash>{inlinesize_toperator()(constpair&v)const{return0;}};在这种情况下,GCC和Clang都可以正常编译,没有任何警告。然而,这似乎与我在网上读到的内容相矛盾,即定义您自己的哈希函数以与标准库的无序类型一起使用需要您将定义放在std命名空间中。有趣的是,专门针对pair:templatestructhash>{size_toperator()(constpair&v)const{size_tseed=0;returnseed;}};如我们所料导致错误。但是,为什

c++ - std::scoped_allocator_adaptor 和一个使用 std::allocator_arg_t 构造函数的类

我在这里找到了一些词http://en.cppreference.com/w/cpp/memory/scoped_allocator_adaptor/constructifstd::uses_allocator::value==true(thetypeTusesallocators,e.g.itisacontainer)andifstd::is_constructible::value==true,thencallsstd::allocator_traits::construct(OUTERMOST(*this),p,std::allocator_arg,inner_allocator