int max(一个变量)和 int max(int ,int)之间没有冲突,这是 C++ 中的一个函数
no conflict between int max,a variable and int max(int ,int),a function in c++
这是一个
有效的代码,即使全局变量max和命名空间std中的函数max(int,int(之间存在冲突。
为什么没有错误?
using namespace std;
int max;
int main()
{
int c;
c=max;
//c=max(5,3);
}
您没有包含 <algorithm>
或任何其他可能声明std::max
的标头,因此没有冲突。程序仅声明一个名为 max
的实体。
如果我包含该标头,则由于歧义,我会收到预期的错误:
test.cpp: In function ‘int main()’:
test.cpp:8:5: error: reference to ‘max’ is ambiguous
c=max;
解决方案是不要将std
转储到全局命名空间中,从而使命名空间的整个用途无效。
相关文章:
- 如何在C++中将一个无符号的 int 转换为两个无符号的短裤?
- int数据类型的指针指向的是什么,如果是一个类的私有数据成员,我们创建了该类的两个对象?
- 包装一个对象并假装它是一个 int
- cin >> int 给定一个字符串将 int 赋值为 0
- 如何创建一个类,以便向量工作 std::vector<MyClass<int>> v{ 1,2,3 };
- 我从int x[3]得到的一个非常奇怪的输出;
- 在 C++11 中利用 int*_t、int_fast*_t 和 int_least*_t 之间的差异的一个很好的例子是
- 为表示一个或多个操作的C++函数的int参数寻找类型安全的替换
- c++:如何打印出一个强制转换的 int 值?
- 通过将其中一个模板更改为 muliset 后,我可以在 PBDS 排序集上使用计数功能<int>less_equal<int>
- 查找不在标准中的第一个值::设置<int>最小-最大值
- 从 int 中剥离位时,编译器会警告一个转换,但不警告其他转换.有解决方法吗?
- 超过CPU时间限制:当MPI_Sent一个非常大的int*时
- 使用无符号int作为二进制来在c++中实现一个集
- 如何声明一个必须在C++中同时存储int和char值的2D数组
- 在int main()[c++]中实现一个递归函数
- 错误:"int pow(double,int)"与上一个声明int pov(double a,int
- CStringArray::GetAt(int index) 返回一个 const. 为什么?
- 打印一个带有静态 int 的函数,有一个 std::cout 和多个 std::cout 有什么区别?
- 将 int 转换为字符串,然后连接另一个变量以创建完整扩展名,然后将其转换为 const_char*