Global variable “count” ambiguous

前端 未结 3 1390
执念已碎
执念已碎 2020-12-05 07:19
#include 
using namespace std;

int count = 0, cache[50];

int f(int n)
{  
    if(n == 2) count++;
    if(n == 0 || n==1) return n;
    else if (ca         


        
3条回答
  •  臣服心动
    2020-12-05 08:10

    The problem is all because of the second line here:

    #include 
    using namespace std;
    

    The line using namespace std brings all the names from which also has a function called count, and in your code, you've declared a variable count. Hence the ambiguous error.

    The solution is to never write using namespace std. It is bad bad bad.

    Instead, use std::cout, std::cin, std::endl, std::count and so on, in your code.

提交回复
热议问题