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

Discussion in 'C++' started by Vikas, Aug 1, 2003.

  1. Vikas

    Vikas Guest

    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
    Vikas, Aug 1, 2003
    #1
    1. Advertising

  2. "Vikas" <> wrote...
    > 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
    Victor Bazarov, Aug 1, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dr Evil

    header file dependency map

    Dr Evil, Aug 19, 2004, in forum: C++
    Replies:
    2
    Views:
    1,099
    Pete Chapman
    Aug 20, 2004
  2. DanielEKFA
    Replies:
    8
    Views:
    606
    DanielEKFA
    May 16, 2005
  3. oor
    Replies:
    0
    Views:
    1,346
  4. mlt
    Replies:
    2
    Views:
    833
    Jean-Marc Bourguet
    Jan 31, 2009
  5. Jun Young Kim
    Replies:
    2
    Views:
    129
    Jun Young Kim
    Nov 13, 2009
Loading...

Share This Page