473,387 Members | 3,787 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Foward referencing broken?

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?
Thanks,
John
Apr 1 '07 #1
5 1344
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
--
Keith Davies "Sometimes my brain is a very strange
ke**********@kjdavies.org to live in."
ke**********@gmail.com -- Dana Smith
http://www.kjdavies.org/
Apr 1 '07 #2
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.
exactly ... there seems to be a missing ";" at the end of a previous
definition or somthing like that.

Apr 1 '07 #3
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
Apr 1 '07 #4
John Watson wrote:
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
There's your problem, missing semicolon.

--
Ian Collins.
Apr 1 '07 #5
John Watson <jo***@lectura.cs.arizona.eduwrote:
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 .

13 struct Task{
14 uint row1, row2;
15 Task *nxt;
16 Task(){}
17 Task(uint in1, uint in2):row1(in1), row2(in2){}
18 }
// ^^ notice a lack of semicolon here
19
20 class AGroup;
The parser sees:

struct Task{
uint row1, row2;
Task *nxt;
Task(){}
Task(uint in1, uint ins):row1(in1), row2(int2){}
} class AGroup;

This confuses the poor thing.

Well, not really *confuses* it. It knows it's wrong. I just doesn't
tell you what caused it.

As a general rule, if you get an error message like this -- any error
message that shows up where you're doing declarations, really -- check
for missing semicolons and mismatched braces ({}) before it. I expect
you'll most often find a missing semi or brace just before it.

At least that's what usually bites me. And it can give a *lot* of error
messages as a result, too.
Keith
--
Keith Davies "Sometimes my brain is a very strange
ke**********@kjdavies.org to live in."
ke**********@gmail.com -- Dana Smith
http://www.kjdavies.org/
Apr 1 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: VK | last post by:
.... or my script, or my mind, or both? <html> <head> <title>Test</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script> function init() { var arr =...
11
by: Edd | last post by:
Hello all, I've made a data structure and an associated set of functions to enable me to store a dynamically-sized array of elements of whatever data type I like. Well that's the idea anyway......
16
by: PromisedOyster | last post by:
Hi I have a situation where I want to use circular referencing. I have cut down the example for demonstration purposes. Say we have one executable (main.exe) and two DLLS (A1.dll and A2.dll)....
6
by: Mikey_Doc | last post by:
Hi We are running cms 2002, Framework 1.0 with Visual studio 2002. We have just upgraded to Framework 1.1 and visual studio 2003. All of our database connection strings are stored within the...
9
by: Brett Romero | last post by:
Say I have a library (A.dll) with a method that accepts a collection of a specific type. The type is defined in B.dll. In A.dll, I need to loop through this collection and reference fields of...
7
by: Mantorok | last post by:
Hi all I have a web-service that references another project (the component) that actually carries out the work, the web-service is simply acting as the public interface. The web-service on...
1
by: TuMultimedia | last post by:
Hello, I make audio slideshows in Flash. They are for non-profits, sometimes they are 8 minutes long and people need to rewind, fast foward to parts on my website. Usually, I just export a simple...
8
by: Chris | last post by:
Hi, i have in an content page a fieldset containing a label, an iframe and a textarea: <asp:Content ID="Content1" ContentPlaceHolderID="main" Runat="Server"> <fieldset style="width:650px;">...
5
by: Matthew Wilson | last post by:
I started off with a module that defined a class Vehicle, and then subclasses Car and Motorcycle. In the Car class, for some bizarre reason, I instantiated a Motorcycle. Please pretend that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.