Wont compile multiple files

Hi

I have a program that should place a number of fish randomly in a "bay", this code compiled fine on the school computers, but i cant get it to compile at home...

fish.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
using namespace std;


class fish
{
 private:
  char type;
  int dir;
 public:
  fish():type('.'),dir(1){}
  fish(char change1, int change2):type(change1),dir(change2){}
  int getdir(){return dir;}
  int setdir(int change){dir=change;}
  char gettype(){return type;}
  char settype(int change){type=change;}
  friend ostream&  operator << (ostream &, fish&);



};





bay.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "fish.h"




class bay
{
private:
fish grid[24][24];
public:
bay();
void placeFish(int numFish);
friend ostream&  operator << (ostream &, bay&);


};




bay.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "bay.h"
#include <cstdlib>
#include <iostream>
#include <ctime>
using namespace std;
bay::bay(){
for(int i=0;i<24;i++)
for(int j=0;j<24;j++)
grid[i][j]=fish();


srand(time(NULL));

}
void bay::placeFish (int numFish)
{

int randrow,randcol;
do
{
randrow=rand()%24;
randcol=rand()%24;
if (grid[randrow][randcol].gettype()=='.')
{
grid[randrow][randcol].settype('F');
numFish--;
}
}
while(numFish>0);


}


ostream&  operator << (ostream & out, bay& fish1)
{
for(int i=0;i<24;i++)
{for(int j=0;j<24;j++)
out << fish1.grid[i][j].gettype() << " ";
out << endl;}

return out;

}


fish.cpp
1
2
3
4
5
6
7
8
9
10
#include "fish.h"

ostream&  operator << (ostream & out, fish& fish1)
{
  out << " the type is " << fish1.type << endl;
  out << " the direction is" << fish1.dir << endl;

  return out;

}


A.cpp

1
2
3
4
5
6
7
8
9
10
#include "fish.h"

int main()
{
  fish f1;
  cout << f1 << endl;
  fish f2('F',3);
  cout << f2 << endl;
  return 0;
}



B.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "bay.h"

int main()
{
bay bay1;
int numFish;
cout << " Enter the num of the fish" << endl;
cin >> numFish;
bay1.placeFish(numFish);
cout << bay1;

return 0;
}


when i compile i get this:

Omar-MacBook-Pro:fish Omar$ g++ A.cpp B.cpp bay.cpp fish.cpp -o fish
ld: duplicate symbol _main in /var/folders/gq/3yhytq9n0bn85ztg7h1fg5b80000gn/T//cc668x73.o and /var/folders/gq/3yhytq9n0bn85ztg7h1fg5b80000gn/T//cc65E7qb.o for architecture x86_64
collect2: ld returned 1 exit status
Omar-MacBook-Pro:fish Omar$
A program can't have more than one main function.
ahhh! duh, forgot we had made 2 programs, i shouldve just compiled B.cpp and bay.cpp
Topic archived. No new replies allowed.