1

what i want to do is when A object enters a new class K it has to exit(deleted from the lists) all of the K(child B and D)s it is in but i get this error just cant figure it out. there is actually a bigger list that lists class K s but i cant reach it by reference(well i can but lots of work not the point)and project has to be circularly dependent

//class A.h
#include some_other_header_circularly_dependent_on_class_B
class B
class A{
public:
    string getname(){return name;};

    void setWhere(K *a){whereami=a;};

    void exit(){
        if(whereami!=NULL)
            (whereami)->exit(name);//error C2227: left of '->exit' must point to class/struct/union/generic type
    };

private:
    K* whereami;
    string name;
};

//class B.h
#include "A.h"
class K{
//abstract functions
}
class B:public class K{
public:
    void enter(A* a){
        a->exit();
        alist.push_front(a);
        a->setWhere(this);
    };
    void exit(string a){
        for(auto it=alist.begin();it!=alist.end();)
            if ((*it)->getname()==a)
                alist.erase(it);
            else it++;
    };
private:
list<A*> alist;
};

feel free to suggest solutions or new designs thanks.

meh
  • 25
  • 1
  • 5

1 Answers1

0

Why not move all method implementations to separate .cpp files and keep only declarations in headers? Then both B.h and A.h can be included in A.cpp and B.cpp

Ilya Kobelevskiy
  • 5,245
  • 4
  • 24
  • 41
  • this is a group project and I'm almost doing it alone i was thinking of giving that part to the other guys that with comments but if it ll to fix my problem i ll do that too – meh Dec 28 '12 at 17:51
  • How is the fact that it is a group project related to design and the question you asked? – Ilya Kobelevskiy Dec 28 '12 at 18:27
  • well it is easy to write just header files while designing the whole thing it is easy to write and fix while nobody is helping anyways this fixed my problem thanks i wasnt sure untill i red http://stackoverflow.com/questions/5363542/complex-circular-dependency – meh Dec 28 '12 at 20:59