Thread: [Dev-C++] Foward declaration
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Luís B. <lf...@ya...> - 2002-05-07 16:50:59
|
I've tried to compiled the following program
with dev-c but it seams that the Migw compiler
does not accept foward declarations. Can anyone
help me?
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
class ClassB;
class ClassA
{
public:
int m_ClassA;
ClassB m_ClassB;
ClassA(void)
{
m_ClassA = 1;
};
void InitializeWith( int iClassA )
{
m_ClassA = iClassA;
m_ClassB.InitializeWith( iClassA );
};
};
class ClassB
{
public:
int m_ClassB;
ClassA m_ClassA;
ClassB(void)
{
m_ClassB = 1;
};
void InitializeWith( int iClassB )
{
m_ClassB = iClassB;
m_ClassA.InitializeWith( iClassB );
};
};
int main(int argc, char *argv[])
{
ClassA TClassA;
ClassB TClassB;
TClassA.InitializeWith( 10 );
TClassB.InitializeWith( 20 );
return 0;
}
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
__________________________________________________
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com
|
|
From: Ioannis V. <no...@ho...> - 2002-05-07 18:10:55
|
ANSI C++ forbids the definition of an object before its type is defined. It's not a compiler problem. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.cjb.net * Alternative URL: http://run.to/noicys > -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf > Of Lums Bras > Sent: Tuesday, May 07, 2002 7:51 PM > To: dev...@li... > Subject: [Dev-C++] Foward declaration > > > I've tried to compiled the following program > with dev-c but it seams that the Migw compiler > does not accept foward declarations. Can anyone > help me? > > +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ > class ClassB; > > class ClassA > { > public: > int m_ClassA; > ClassB m_ClassB; > ClassA(void) > { > m_ClassA = 1; > }; > void InitializeWith( int iClassA ) > { > m_ClassA = iClassA; > m_ClassB.InitializeWith( iClassA ); > }; > }; > > class ClassB > { > public: > int m_ClassB; > ClassA m_ClassA; > ClassB(void) > { > m_ClassB = 1; > }; > void InitializeWith( int iClassB ) > { > m_ClassB = iClassB; > m_ClassA.InitializeWith( iClassB ); > }; > }; > > int main(int argc, char *argv[]) > { > ClassA TClassA; > ClassB TClassB; > > TClassA.InitializeWith( 10 ); > TClassB.InitializeWith( 20 ); > > return 0; > } > +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ > > __________________________________________________ > Do You Yahoo!? > Yahoo! Health - your guide to health and wellness > http://health.yahoo.com > > _______________________________________________________________ > > Have big pipes? SourceForge.net is looking for download > mirrors. We supply > the hardware. You get the recognition. Email Us: > ban...@so... > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
|
From: Ricardo R. <ri...@po...> - 2002-05-07 18:47:43
|
Then, is there no possibility to program something as Luis Bras propose??...Some special trick, I mean. Ricardo. |
|
From: Ioannis V. <no...@ho...> - 2002-05-07 19:22:54
|
I suppose the question was for me and i suppose the question is to have
2 classes one containing an object of the other (i did not pay much
attention when i saw the code).
Well this cannot be done and it is good it can't be done, because then
the computers would crash. :)
Imagine the code:
class B;
class A
{
B b;
};
class B
{
A a;
};
A contains a B which contains an A which contains a B...
That's why it can't be done.
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
* Alternative URL: http://run.to/noicys
> -----Original Message-----
> From: dev...@li...=20
> [mailto:dev...@li...] On Behalf=20
> Of Ricardo L=F3pez Ruiz
> Sent: Tuesday, May 07, 2002 9:45 PM
> To: Dev-C++
> Subject: Re: [Dev-C++] Foward declaration
>=20
>=20
> Then, is there no possibility to program something
> as Luis Bras propose??...Some special trick, I mean.
>=20
> Ricardo.
>=20
>=20
> _______________________________________________________________
>=20
> Have big pipes? SourceForge.net is looking for download=20
> mirrors. We supply
> the hardware. You get the recognition. Email Us:=20
> ban...@so...
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>=20
|
|
From: Shaddow <sh...@ti...> - 2002-05-07 20:24:04
|
I didn't see the original question so I may be answering something that
hasn't actually been asked. If so, just ignore what I have to say.
While it's true that you'd get yourself into all kinds of trouble trying
to have A be a data member of B and B a data member of A, it is entirely
possible (and actually at times necessary) to have B* be a data member
of A and A* be a data member of B. You see this kind of a situation
frequently in frameworks.
class B;
class A
{
B* b;
};
class B
{
A* a;
};
Ioannis Vranos wrote:
>I suppose the question was for me and i suppose the question is to have
>2 classes one containing an object of the other (i did not pay much
>attention when i saw the code).
>
>
>Well this cannot be done and it is good it can't be done, because then
>the computers would crash. :)
>
>
>Imagine the code:
>
>class B;
>
>class A
>{
> B b;
>
>};
>
>class B
>{
> A a;
>};
>
>
>A contains a B which contains an A which contains a B...
>
>
>That's why it can't be done.
>
>Ioannis
>
>* Ioannis Vranos
>* Programming pages: http://www.noicys.cjb.net
>* Alternative URL: http://run.to/noicys
>
>
>>-----Original Message-----
>>From: dev...@li...
>>[mailto:dev...@li...] On Behalf
>>Of Ricardo Lσpez Ruiz
>>Sent: Tuesday, May 07, 2002 9:45 PM
>>To: Dev-C++
>>Subject: Re: [Dev-C++] Foward declaration
>>
>>
>>Then, is there no possibility to program something
>>as Luis Bras propose??...Some special trick, I mean.
>>
>>Ricardo.
>>
>>
>>_______________________________________________________________
>>
>>Have big pipes? SourceForge.net is looking for download
>>mirrors. We supply
>>the hardware. You get the recognition. Email Us:
>>ban...@so...
>>_______________________________________________
>>Dev-cpp-users mailing list
>>Dev...@li...
>>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>>
>
>_______________________________________________________________
>
>Have big pipes? SourceForge.net is looking for download mirrors. We supply
>the hardware. You get the recognition. Email Us: ban...@so...
>_______________________________________________
>Dev-cpp-users mailing list
>Dev...@li...
>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: Ioannis V. <no...@ho...> - 2002-05-07 20:54:40
|
Yes, that's rational. I explained why 2 classes can't have objects of
one another both at the same time (1 object occupies at least one byte
even if it belongs to an empty class:
=20
class emtpy{};
=20
).
=20
So it was a situation with an infinite number of objects (and memory)
so it correctly doesn't compile. The situation you describe is ok.
=20
=20
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
<http://www.noicys.cjb.net/>=20
* Alternative URL: http://run.to/noicys
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...] On Behalf Of Shaddow
Sent: Tuesday, May 07, 2002 11:24 PM
To: dev...@li...
Subject: Re: [Dev-C++] Foward declaration
I didn't see the original question so I may be answering something that
hasn't actually been asked. If so, just ignore what I have to say.
While it's true that you'd get yourself into all kinds of trouble trying
to have A be a data member of B and B a data member of A, it is entirely
possible (and actually at times necessary) to have B* be a data member
of A and A* be a data member of B. You see this kind of a situation
frequently in frameworks.
class B;
class A
{
B* b;
};
class B
{
A* a;
};
Ioannis Vranos wrote:
I suppose the question was for me and i suppose the question is to have
2 classes one containing an object of the other (i did not pay much
attention when i saw the code).
Well this cannot be done and it is good it can't be done, because then
the computers would crash. :)
Imagine the code:
class B;
class A
{
B b;
};
class B
{
A a;
};
A contains a B which contains an A which contains a B...
That's why it can't be done.
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
* Alternative URL: http://run.to/noicys
-----Original Message-----
From: dev...@li...=20
[mailto:dev...@li...] On Behalf=20
Of Ricardo L=F3pez Ruiz
Sent: Tuesday, May 07, 2002 9:45 PM
To: Dev-C++
Subject: Re: [Dev-C++] Foward declaration
Then, is there no possibility to program something
as Luis Bras propose??...Some special trick, I mean.
Ricardo.
_______________________________________________________________
Have big pipes? SourceForge.net is looking for download=20
mirrors. We supply
the hardware. You get the recognition. Email Us:=20
ban...@so...
_______________________________________________
Dev-
cpp-users mailing list
Dev...@li...
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
_______________________________________________________________
Have big pipes? SourceForge.net is looking for download mirrors. We
supply
the hardware. You get the recognition. Email Us:
ban...@so...
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|
|
From: staale <st...@le...> - 2002-05-07 21:42:41
|
Search for 'how to handel Circular references' or somthing like that. I =
also belive this situation usualy is discussed in a decent 'Design =
patterns' book.
MVH
Staale
----- Original Message -----=20
From: Shaddow=20
To: dev...@li...=20
Sent: Tuesday, May 07, 2002 10:24 PM
Subject: Re: [Dev-C++] Foward declaration
I didn't see the original question so I may be answering something =
that hasn't actually been asked. If so, just ignore what I have to say.
While it's true that you'd get yourself into all kinds of trouble =
trying to have A be a data member of B and B a data member of A, it is =
entirely possible (and actually at times necessary) to have B* be a data =
member of A and A* be a data member of B. You see this kind of a =
situation frequently in frameworks.
class B;
class A
{
B* b;
};
class B
{
A* a;
};
Ioannis Vranos wrote:
I suppose the question was for me and i suppose the question is to have2 =
classes one containing an object of the other (i did not pay =
muchattention when i saw the code).Well this cannot be done and it is =
good it can't be done, because thenthe computers would crash. :)Imagine =
the code:class B;class A{ B b;};class B{ A a;};A contains a B which =
contains an A which contains a B...That's why it can't be done.Ioannis* =
Ioannis Vranos* Programming pages: http://www.noicys.cjb.net* =
Alternative URL: http://run.to/noicys
-----Original Message-----From: =
dev...@li... =
[mailto:dev...@li...] On Behalf Of Ricardo =
L=F3pez RuizSent: Tuesday, May 07, 2002 9:45 PMTo: Dev-C++Subject: Re: =
[Dev-C++] Foward declarationThen, is there no possibility to program =
somethingas Luis Bras propose??...Some special trick, I =
mean.Ricardo.____________________________________________________________=
___Have big pipes? SourceForge.net is looking for download mirrors. We =
supplythe hardware. You get the recognition. Email Us: =
bandwidth@sourceforge.net_______________________________________________D=
ev-
cpp-users mailing =
lis...@li...://lists.sourceforge.net/list=
s/listinfo/dev-cpp-users
_______________________________________________________________Have big =
pipes? SourceForge.net is looking for download mirrors. We supplythe =
hardware. You get the recognition. Email Us: =
bandwidth@sourceforge.net_______________________________________________D=
ev-cpp-users mailing =
lis...@li...://lists.sourceforge.net/list=
s/listinfo/dev-cpp-users
|
|
From: Ricardo R. <ri...@po...> - 2002-05-08 09:56:40
|
Yes, I see. There is one possibility: using pointers, isn't it?. The solution seems similar to the case of self-referenced structures: when you build a linked list or a binary tree you need a solution like that. Ricardo. |