How to remove dependency on a header file which has a typedef?

V

Vikas

I have a header file say A.h in which I have typedefed

typedef std::vector<std::string> StringVector;

Now there is second file say B.h in which a class B has a method

class B {
....
ParseData(const StringVector::const_iterator& begin, const
StringVector::const_iterator& end);

};

Now without #including A.h in B.h, how can I declare
StringVector::const_iterator properly in B.h. I tried to do a forward
declaration in B.h but I get compilation errors.

// Following gives compilation errors if I put it in B.h
Class StringVector::const_iterator;

Thank you for your replies.

Vikas
 
V

Victor Bazarov

Vikas said:
I have a header file say A.h in which I have typedefed

typedef std::vector<std::string> StringVector;

Now there is second file say B.h in which a class B has a method

class B {
...
ParseData(const StringVector::const_iterator& begin, const
StringVector::const_iterator& end);
.
};

Now without #including A.h in B.h, how can I declare
StringVector::const_iterator properly in B.h.

Put the typedef in C.h and #include C.h in both A.h and B.h.
I tried to do a forward
declaration in B.h but I get compilation errors.

// Following gives compilation errors if I put it in B.h
Class StringVector::const_iterator;

'Class' is not C++. 'class' would be C++. Although, there is no
forward-declaration of members in C++, anyway.

Victor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top