Random question

So I was coding and came across an issue.

Basically, I have some typedefs in class A that I would like to use in another class B. However, class B contains an instance of A (technically class C deriving from A), so I obviously can't include B in A to get it to work. What should I do here?
Uh... What? If B contains C which derives from A, then B.h should already see A.h.
Sorry, class A contains an instance of class B, not the other way around. Whoops.
Do you need to use the typedefs in the header? If not, you can just include A.h in B.cpp.
Yeah, I need to use them in the header.
Bump.
Are the typedefs actually in your class?

1
2
3
4
5
6
class test{
protected:
    typedef int* iptr;
public:
    iptr tst;
};


or are they just in the same file?

If the case is the latter (which would make more sense to me) then you could simply make another header file with the typedef(s) in it, and include said header in both other headers (I would think)

unless of course you are making a typedef of the class...

1
2
3
4
5
6
7
8
9
10
template<class C>
class test{
protected:
    typedef C* iptr;
public:
    iptr tst;
};


typedef test<int> purple;


In which case... Why? That would be very circular...
Last edited on
It's a normal type and it's inside the class.
Does it have to be in the class? Can you drop it out?
It's part of the class, like "ElemType" in string. :/
Put it in a trait class. Something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class A;
class B;

template <class T>
struct Traits;

template<>
struct Traits<A>
{
    typedef char ElemType;
};

class B
{
    Traits<A>::ElemType elem1;
};

class A
{
    Traits<A>::ElemType elem2;
    B b;
}; 
Topic archived. No new replies allowed.