RE: C++

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I think you just need a

class A;

decalration at the top of the file.

Jon

On Mon, 24 Feb 2003, Narayanan Krishnan wrote:

> Definining prototypes for functions/classes can solve this problem.
>
> You should be able to define a class 'prototype' right at the top for class B before definining the class A followed by definition for class B.
>
>
>
> -----Original Message-----
> From: Thomas Dodd [mailto:ted@cypress.com]
> Sent: Monday, February 24, 2003 10:21 AM
> To: psyche-list@redhat.com; redhat-devel-list@redhat.com;
> mozilla-builds@mozilla.org
> Subject: C++
>
>
>  I had a question for a C++ programmer. Thought I might find one here :)
>
>
> I have 2 classes that need to reference each other.
>
> "headerA.h"
> class A{
> public:
>    int x;
>    int y;
>    B *left;
>    B *right;
> }
>
> "headerB.h"
> class B{
> public:
>    int a;
>    int b;
>    A *parent;
>    char foo();
> }
>
> Give that top is of type A, in top.left.foo() I need to modify top.right.a
>
> Any ideas? I've tried passing a A* in the constructor for B, but the
> compiler doesn't
> realize that A is a class when I try to compile, and complains about no
> type listed.
>
> I seams to be a circular reference since A needs B and B needs A. This
> cannot be that
> unusual, and has probably been solved before, I just don't know how.
>
> Right now moy only though is to make parent a void* and the cast it to a
> A* in the
> implementation of B. That removes all type checking though and I'd
> rather not abuse
> void pointers like that.
>
>     -Thomas
>
>
>
>
> _______________________________________________
> Redhat-devel-list mailing list
> Redhat-devel-list@redhat.com
> https://listman.redhat.com/mailman/listinfo/redhat-devel-list
>
>
>
> _______________________________________________
> Redhat-devel-list mailing list
> Redhat-devel-list@redhat.com
> https://listman.redhat.com/mailman/listinfo/redhat-devel-list
>



_______________________________________________
Redhat-devel-list mailing list
Redhat-devel-list@redhat.com
https://listman.redhat.com/mailman/listinfo/redhat-devel-list

[Index of Archives]     [Kernel Newbies]     [Red Hat General]     [Fedora]     [Red Hat Install]     [Linux Kernel Development]     [Yosemite News]

  Powered by Linux