#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];
}
Ho usato questa funzione con gcc 4.3.4, e ottenuto il seguente errore:variabile globale "contare" ambiguo
prog.cpp: In function ‘int f(int)’:
prog.cpp:38: error: reference to ‘count’ is ambiguous
sulla mia macchina locale (mingw32), l'errore ho ottenuto è stato this one, anche se non è per int 'cache[]'
.
Qualsiasi motivo per cui?
È questo codice C o codice C++? –
@DavidSchwartz questo è il codice C++, ma lo stesso problema si è verificato anche in C. – Amit
@DavidSchwartz: [Does not] (http://ideone.com/qNKQI) [matter] (http://ideone.com/6cEXW). – ildjarn