Take this code for example
Code:
#define upleft buffer[a-1][b-1]
#define upcent buffer[a-1][b]
#define upright buffer[a-1][b+1]
#define left buffer[a][b-1]
#define right buffer[a][b+1]
#define loleft buffer[a+1][b-1]
#define locent buffer[a+1][b]
#define loright buffer[a+1][b+1]
class intertia
{
public:
double a,b;
intertia() {a=b=0;}
void calculate()
{
a++;
if(upleft==1) {b-=.3;}
if(upright==1) {b+=.3;}
if(left==1) {b-=.3;}
if(right==1) {b+=.3;}
if(loleft==1) {b-=.3;}
if(loright==1) {b+=.3;}
}
};
int main()
{
int buffer[70][70];
memset(buffer,0,sizeof(buffer));
intertia inert[70][70];
//...
The compiler complains that it doesn't know the identifier 'buffer'. Yet, the function that calls 'buffer' is not even called. Why would it complain if it doesn't need to use it yet? Buffer is declared by the time any object is constructed...
I suppose the answer to my question is that yes, the class checks to see if it knows variables before any object is even constructed. But could anyone reassure me on that fact? Why is it implemented this way, making the code above have errors?
Thanks a lot for the help