I edited the class names to be ACell and AGroup just in case they were
clashing with the include files. Again, the error occurs on line 20 w/
G++ spitting: Conc.cpp:20: error: multiple types in one declaration .
01 #include <iostream>
02 #include <pthread.h>
03 #include <semaphore.h>
04 #include <sstream>
05 #include <iomanip>
06 #include <fstream>
07 #include <sys/time.h>
08 #include <vector>
09 #define SHARED 1
10 typedef unsigned int uint;
11 using namespace std;
12
13 struct Task{
14 uint row1, row2;
15 Task *nxt;
16 Task(){}
17 Task(uint in1, uint in2):row1(in1), row2(in2){}
18 }
19
20 class AGroup;
21
22 class ACell{
23 public:
24 uint val;
25 AGroup *group;
26 ACell();
27 ACell(uint inval, AGroup *g);
28 };
29
30 class AGroup{
31 uint val;
32 vector<ACell *members;
33 public:
34 AGroup(uint in); //: val(in) {}
35 void swap(AGroup *newAGroup);
36 void add(ACell *inACell); //{ members.push_back(inACell);}
37 uint value(); // {return val;}
38 };
39
40 ACell::ACell(){ group = NULL;}
41 ACell::ACell(uint inval, AGroup *g): val(inval), group(g){}
42
43 AGroup::AGroup(uint in): val(in) {}
44 void AGroup::swap(AGroup *newAGroup){
45 //iterate through all members and change their AGroup to newAGroup
46 size_t size = members.size();
47 vector<ACell *>::iterator firstElement;
48 for(int i = 0; i < size; i++){
49 firstElement = members.begin();
50 (*firstElement)->group = newAGroup;
51 newAGroup->add(*firstElement);
52 members.erase(firstElement);
53 }
54 }
55 void AGroup::add(ACell *inACell){members.push_back(inACell);}
56 uint AGroup::value() {return val;}
What gives?
-John Watson
On Sun, 1 Apr 2007, Keith Davies wrote:
John Watson <jo***@lectura.cs.arizona.eduwrote:
>I can find no error w/ the code below but g++ complains that:
22: error: multiple types in one declaration
22 class Group;
23
24 class Cell{
25 public:
26 uint val;
27 Group *group;
28 Cell();
29 Cell(uint inval, Group *g);
30 };
31
32 class Group{
33 uint val;
34 vector<Cell *members;
35 public:
36 Group(uint in); //: val(in) {}
37 void swap(Group *newGroup);
38 void add(Cell *inCell); //{ members.push_back(inCell);}
39 uint value(); // {return val;}
40 };
I need to forward declare class Group for class Cell to have a pointer to
that class. Does anyone know how to deal with two classes referencing
eachother?
What happens before line 22? What I see here all looks okay,
declaration-wise.
Keith