error C2039: “difference_type”: 不是“`global namespace‘”的成员

在VS2013运行出现了这个错误,但是换到g++编译就没有问题了。

百度一波没找到解决方法,排除法找到了错误,原来是count函数,

如果你重载了一个三个参数的count函数(当然你传的参数只要不是已经有的重载函数即可),

会编译如上图错误。

count这个函数是<algorithim>内用于计算容器内元素数目的函数。

下面的代码就会编译错误。

当然你可能与其他函数冲突了,建议使用排除法来找到错误。

#include<bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
const int mod = 1e9 + 7;
typedef long long ll;

void count(int a, int b, int c)
{
	cout << a << endl;
}
int main()
{
#ifdef LOCAL
	freopen("E:/input.txt", "r", stdin);
#endif
	count(1, 1, 1);
	return 0;
}

下面的就可以运行。

#include<bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
const int mod = 1e9 + 7;
typedef long long ll;

void count(int a, int b)
{
	cout << a << endl;
}
void count(int a, int b, int c, int d)
{
	cout << a << endl;
}
int main()
{
#ifdef LOCAL
	freopen("E:/input.txt", "r", stdin);
#endif
	count(1, 1);
	count(1, 1, 1, 1);
	return 0;
}

找到错误之后可以选择,改变参数,避免跟库函数重载相同的函数,或者改变函数名称来解决。

 

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值