Internal typedef and circular dependency

Posted by bcr on Stack Overflow See other posts from Stack Overflow or by bcr
Published on 2013-11-06T00:49:18Z Indexed on 2013/11/06 3:54 UTC
Read the original article Hit count: 107

I have two classes whose functions take typedefed pointers to eachother as return values and parameters. I.e.:

class Segment;

class Location : public Fwk::NamedInterface {
  public:
    // ===== Class Typedefs =====
    typedef Fwk::Ptr<Location const> PtrConst;
    typedef Fwk::Ptr<Location> Ptr;
    // ===== Class Typedefs End =====
    void segmentIs(Segment::Ptr seg);
    /* ... */
}

and class Location;

class Segment : public Fwk::NamedInterface {
  public:
    // ===== Class Typedefs =====
    typedef Fwk::Ptr<Segment const> PtrConst;
    typedef Fwk::Ptr<Segment> Ptr;
    // ===== Class Typedefs End =====
    void locationIs(Location::Ptr seg);
    /* ... */
 }

This understandably generated linker errors...which the forward declarations of the respective classes don't fix. How can I forward declare the Ptr and PtrConst typedefs while keeping these typedefs internal to the class (i.e. I would like to write Location::Ptr to refer to the location pointer type)?

Thanks folks!

© Stack Overflow or respective owner

Related posts about c++

Related posts about include