A
abir
Hi,
I have some circular dependency problem while having these 3
classes.
1) class Context holds vector of Char & Word
2) Char class has index of Word to which it belongs, in the vector &
a ref to Context
3) Word class has 2 index denoting begin & end char for the Word in
the vector & a ref to context.
Now, Char class wants to return the pointer to Word (iterator)
and Word class wants to return a pair of iterator saying the set of
Char's for it.
eg,
#include "Word.h"
#include "Char.h"
struct Context{
std::vector<Word> words_;
std::vector<Char> chars_;
};
//Word.h
class Context;
struct Word{
std::size_t begin;
std::size_t end;
Context& ctx_;
Word(Context& ctx) :ctx_(ctx){}
std:
air<vector<Char>::iterator,vector<Char>::iterator > chars();//i
need to include Char.h for this
std:
air<Char*,Char*> chars();///This version works with
forward declaration.
};
//Char.h
struct Char{
std::size_t word;
vector<Word>::iterator word();///i need to include Word.h for
this
Word* word();///This works, and equiv to above function for
vector.
};
Now as I can't forward declare iterator for vector , Word & Char goes
for cyclic dependency,
However if i return a pointer to Word and Char (any one breaks
dependency problem), which works for case of vector, the problem is
not there.
Can anyone specify how to have it in terms of iterator ?
Thanks
abir
I have some circular dependency problem while having these 3
classes.
1) class Context holds vector of Char & Word
2) Char class has index of Word to which it belongs, in the vector &
a ref to Context
3) Word class has 2 index denoting begin & end char for the Word in
the vector & a ref to context.
Now, Char class wants to return the pointer to Word (iterator)
and Word class wants to return a pair of iterator saying the set of
Char's for it.
eg,
#include "Word.h"
#include "Char.h"
struct Context{
std::vector<Word> words_;
std::vector<Char> chars_;
};
//Word.h
class Context;
struct Word{
std::size_t begin;
std::size_t end;
Context& ctx_;
Word(Context& ctx) :ctx_(ctx){}
std:
need to include Char.h for this
std:
forward declaration.
};
//Char.h
struct Char{
std::size_t word;
vector<Word>::iterator word();///i need to include Word.h for
this
Word* word();///This works, and equiv to above function for
vector.
};
Now as I can't forward declare iterator for vector , Word & Char goes
for cyclic dependency,
However if i return a pointer to Word and Char (any one breaks
dependency problem), which works for case of vector, the problem is
not there.
Can anyone specify how to have it in terms of iterator ?
Thanks
abir