#include <algorithm>
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 (cache[n] !=- 1) return cache[n];
else cache[n]= f(n-1) + f(n-2);
return cache[n];
}
użyłem tej funkcji z gcc 4.3.4 i uzyskałem następujący błąd:zmienna globalna "liczyć" niejednoznaczne
prog.cpp: In function ‘int f(int)’:
prog.cpp:38: error: reference to ‘count’ is ambiguous
Na moim komputerze lokalnym (mingw32), błąd Dostałem this one, chociaż nie jest to dla int 'cache[]'
.
Każdy powód dlaczego?
Czy to jest kod C, czy kod C++? –
@DavidSchwartz to jest kod C++, ale ten sam problem również wystąpił w języku C. – Amit
@DavidSchwartz: [Nie] (http://ideone.com/qNKQI) [sprawa] (http://ideone.com/6cEXW). – ildjarn