I have a program for distance vector routing as shown below (though, what the program is for is not important here). The problem is when I run this program using Turbo C++ compiler on Windows, it works perfectly fine.
But when I compile this using gcc on Fedora 9 (as you can see the 'r' I have used in the function build of the 'router' class) the compiler tells that it is used before the declaration, but in turbo c++ it's fine.
Any options to get through this error in gcc compiler, or any modifications to the function to perform the same task? Please, please, help me - in a very needy state - help will be remembered...
#include <conio.h>
#include <iostream.h>
#define MAX 10
int n;
class router {
char adj_new[MAX], adj_old[MAX];
int table_new[MAX], table_old[MAX];
public:
router(){
for(int i=0;i<MAX;i++) table_old[i]=table_new[i]=99;
}
void copy(){
for(int i=0;i<n;i++) {
adj_old[i] =adj_new[i];
table_old[i]=table_new[i];
}
}
int equal() {
for(int i=0;i<n;i++)
if(table_old[i]!=table_new[i]||adj_new[i]!=adj_old[i])return 0;
return 1;
}
void input(int j) {
cout<<"Enter 1 if the corresponding router is adjacent to router"
<<(char)('A'+j)<<" else enter 99: "<<endl<<" ";
for(int i=0;i<n;i++)
if(i!=j) cout<<(char)('A'+i)<<" ";
cout<<"\nEnter matrix:";
for(i=0;i<n;i++) {
if(i==j)
table_new[i]=0;
else
cin>>table_new[i];
adj_new[i]= (char)('A'+i);
}
cout<<endl;
}
void display(){
cout<<"\nDestination Router: ";
for(int i=0;i<n;i++) cout<<(char)('A'+i)<<" ";
cout<<"\nOutgoing Line: ";
for(i=0;i<n;i++) cout<<adj_new[i]<<" ";
cout<<"\nHop Count: ";
for(i=0;i<n;i++) cout<<table_new[i]<<" ";
}
void build(int j) {
for(int i=0;i<n;i++)
for(int k=0;(i!=j)&&(k<n);k++)
if(table_old[i]!=99)
if((table_new[i]+r[i].table_new[k])<table_new[k]) {
table_new[k]=table_new[i]+r[i].table_new[k];
adj_new[k]=(char)('A'+i);
}
}
} r[10];