对于您可以包括的所有其他标准库头,有必要通过以下任一方法指定命名空间:
using namespace std;
using std::xxx;
int main() {
std::xxx;
}
到目前为止,我遇到的唯一例外是在<cmath>库中,我到目前为止使用的所有函数都不需要上述任何函数,以便在不指定名称空间的情况下使用它们。为什么会这样呢?
注意:我认为<cmath>是惟一不需要指定名称空间的标准库头,或者<cmath>中的每个函数都是这样的,这可能是错误的。我只是在日常使用中还没有遇到异常情况。
Visual Studio Professional 2013
Windows 7
x32,x64处理器
我正在使用DirectX 11,并且似乎有一个奇怪的问题。我一直能够访问我的应用程序中的DirectX命名空间。现在情况不再是这样了。我可以做一个简单的课程
// A.h
#include <d3d11.h>
#pragma comment(lib, "d3d11.lib")
class A {
}
如果我尝试使用完全引用的类型
DirectX::ID3D11Device* mDevice;
我也没有使用intellisense来显示DirectX名称空间
这是对另一个的后续。
最初的问题还有其他问题,但我不得不意识到,主要的问题(根据CLang)是将time重新定义为一个不同的符号,而使用的只有漂亮的C++。
下面是一个精简的版本:
#include<iostream>
using std::cout;
using std::endl;
class time
{
public:
int h, min, sec;
};
const int full = 60;
void canonify(time& pre) // Error here (line 14)
{
pre.min += pre.se
我编写了以下代码:
#include <iostream>
inline namespace M
{
int j=42;
}
int main(){ std::cout << j << "\n"; } //j is unqualified name here.
//Hence, unqualified name lookup rules will be applied.
//This implies that mem
我正在寻找一个与PHP中的相当的JavaScript,以允许我获得当前函数的名称。例如:
function foo(){
console.log(__FUNCTION__); // "foo" would be logged to the console
}
在JavaScript中有办法做到这一点吗?或者使用类似于__FUNCTION__的神奇变量或者任何其他解决方法?而且,如果目前没有办法实现这一目标,它是否计划
我有过,
时间h:
#pragma once
#ifndef TIME_H
#define TIME_H
class time
{
private:
int hour;
int minute;
int second;
public:
enum pmORam {am,pm};
time(void);
time(int,int,int);
void printtime(void);
time subtime(time &);
const time &operator=(const time &);
看看这个小程序。
#include <iostream>
int main(){
int var = atoi("-99"); //convert string to int
var = abs(var); //takes absolute value
std::cout << var+1 <<'\n'; //outputs 100
return EXIT_SUCCESS;
}
编译将创建以下错误消息:
$ g++ -o main main.cpp
main.cpp: