相关疑难解决方法(0)

为什么每个人都使用unanchored名称空间声明(即std :: not :: std::)?

在我看来,当有人放入一个恰好与根级命名空间同名的新命名空间并且神秘地改变了许多程序的含义时,使用未锚定的命名空间只会引发麻烦.那么,为什么人们总是说std::而不是::std::.他们真的应该说"我想用任何std方便的东西,而不是根本的东西."?

这是我的意思的一个例子:

在fred/Foo.h中:

#include <string>

namespace fred {

class Foo {
 public:
   void aPublicMember(const std::string &s);
};

} // end namespace fred
Run Code Online (Sandbox Code Playgroud)

在fred/Bar.h中:

namespace fred {
namespace std {  // A standard fred component

class string { // Something rather unlike the ::std::string
   // ...
};

} // namespace std

class Bar {
 public:
   void aPublicMember(std::string &s);
};

} // namespace fred
Run Code Online (Sandbox Code Playgroud)

在oops.cpp中:

#include <string>
#include "fred/Bar.h"
#include "fred/Foo.h"  // Oops, the meaning of …
Run Code Online (Sandbox Code Playgroud)

c++ namespaces

28
推荐指数
3
解决办法
4021
查看次数

C++字符串文字数据类型存储

void f()
{
    char *c = "Hello World!"
}
Run Code Online (Sandbox Code Playgroud)

字符串存储在哪里?它的属性是什么?我只知道它是一个常数,还有什么?我可以从功能体内部返回吗?

c++ memory compiler-construction storage types

21
推荐指数
4
解决办法
4935
查看次数

标签 统计

c++ ×2

compiler-construction ×1

memory ×1

namespaces ×1

storage ×1

types ×1