On 2008-05-03 10:36:50 -0400, "barcaroller" <barcaroller@[EMAIL PROTECTED]
> said:
>
> "Pete Becker" <pete@[EMAIL PROTECTED]
> wrote in message
> news:2008050310124475249-pete@[EMAIL PROTECTED]
>>
>> At the point of "new A" the compiler has to generate code to create an
>> object of tpye A. Since it hasn't seen the definition of A, it can't do
>> that.
>
>
> Thank you for your response. Actually, it's not the new() that is
causing
> me problems. Let me present the problem in another way.
>
>
> class A; // forward reference
>
> class B
> {
> int print()
> {
>
> }
>
> foo(A* a)
> {
> cout << a->print(); // compiler error here
> }
> }
At the point of the call to a->print() the compiler has to generate
code to call a member function of an object of type A. Since it hasn't
seen the definition of A, it can't do that.
>
> Basically, I have two objects that are dependent on each other. I
thought I
> would be okay as long as I use pointers to these objects. Is there a
way
> around this problem (other than re-designing)?
Yup. Move the definition of B::foo outside the class definition, after
the definition of A.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)


|