Headers cross-calling

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mail.To.Nathaniel@gmail.com

    #1

    Headers cross-calling

    Hi all :)

    I have an-easy-to-resolve (I am sure but I am obviously unable to
    figure the answer out) problem for C++ gurus.

    Here's the situation I have fallen into...

    2 header files: H1.h & H2.h
    --------------------------------------------------------------------
    --- H1.h
    --------------------------------------------------------------------
    #include "H2.h" // <------ error at compilation (unknown type:
    T1c in the T2),
    // without the #include: unknown
    type T2 in the T11
    class T11
    {
    <...>
    T2 method();
    }

    template <typename Tclass T12 :
    : T11
    {
    <...>
    }

    typedef T1<charT1c;
    --------------------------------------------------------------------
    --- H2.h
    --------------------------------------------------------------------
    #include "H1.h"

    class T2
    {
    <...>
    void method(T1c);
    }
    --------------------------------------------------------------------

    Is it possible to resolve the conflict described? Or should I find a
    way to avoid this kind of cross calls?

    Thanks for any help :)

  • Victor Bazarov

    #2
    Re: Headers cross-calling

    Mail.To.Nathani el@gmail.com wrote:
    I have an-easy-to-resolve (I am sure but I am obviously unable to
    figure the answer out) problem for C++ gurus.
    >
    Here's the situation I have fallen into...
    >
    2 header files: H1.h & H2.h
    --------------------------------------------------------------------
    --- H1.h
    --------------------------------------------------------------------
    #include "H2.h" // <------ error at compilation (unknown type:
    T1c in the T2),
    // without the #include: unknown
    type T2 in the T11
    class T11
    {
    <...>
    T2 method();
    Change to

    class T2 method();
    }
    >
    template <typename Tclass T12 :
    : T11
    {
    <...>
    }
    >
    typedef T1<charT1c;
    --------------------------------------------------------------------
    --- H2.h
    --------------------------------------------------------------------
    #include "H1.h"
    >
    class T2
    {
    <...>
    void method(T1c);
    Change to

    void method(class T1c);
    }
    --------------------------------------------------------------------
    >
    Is it possible to resolve the conflict described? Or should I find a
    way to avoid this kind of cross calls?
    You don't have to avoid them. Read about forward declarations.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask


    Comment

    • Mail.To.Nathaniel@gmail.com

      #3
      Re: Headers cross-calling

      I have replaced
      void method(T1c);
      by
      void method(T1<char> );

      Is it a good decision?

      Comment

      • Victor Bazarov

        #4
        Re: Headers cross-calling

        Mail.To.Nathani el@gmail.com wrote:
        I have replaced
        void method(T1c);
        by
        void method(T1<char> );
        >
        Is it a good decision?
        Any decision that moves you closer to your goal is good.


        Comment

        • Mail.To.Nathaniel@gmail.com

          #5
          Re: Headers cross-calling

          On 11 , 15:11, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
          Mail.To.Nathan. ..@gmail.com wrote:
          I have replaced
          void method(T1c);
          by
          void method(T1<char> );
          >
          Is it a good decision?
          >
          Any decision that moves you closer to your goal is good.
          It could be an "it-works-but-you-should-never-do-this" solution :)

          Anyway, :D

          Comment

          • Victor Bazarov

            #6
            Re: Headers cross-calling

            Mail.To.Nathani el@gmail.com wrote:
            On 11 , 15:11, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
            >Mail.To.Nathan ...@gmail.com wrote:
            >>I have replaced
            >> void method(T1c);
            >>by
            >> void method(T1<char> );
            >>
            >>Is it a good decision?
            >>
            >Any decision that moves you closer to your goal is good.
            >
            It could be an "it-works-but-you-should-never-do-this" solution :)
            OK, I took another look and think that your solution does not really
            fall into that category. However, there is something to be said, of
            course. 'T1c' is a typedef in the header you didn't (or couldn't)
            include. Why is it a typedef? At some point the decision was made
            to have a typedef instead of forcing the user type 'T1<char>'. Was
            that to save typing or was there other reason? If it was to save
            typing, replacing 'T1c' with 'T1<char>' in the declaration above is
            perfectly OK. However, if it was because on some systems 'T1c' can
            be something else (and not necessarily 'T1<char>'), and the choice
            has to be governed by some #define or whatever other means, then
            being explicit here may not be what you need. The latter case is,
            admittedly, unlikely.

            V
            --
            Please remove capital 'A's when replying by e-mail
            I do not respond to top-posted replies, please don't ask


            Comment

            • Mail.To.Nathaniel@gmail.com

              #7
              Re: Headers cross-calling

              It was only a user-confort choice allowing for shorter type names. So
              everything seems OK now.

              Thank you really very much for your help and attention.

              Spasibo :)


              On 11 , 16:02, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
              Mail.To.Nathan. ..@gmail.com wrote:
              On 11 , 15:11, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
              Mail.To.Nathan. ..@gmail.com wrote:
              >I have replaced
              > void method(T1c);
              >by
              > void method(T1<char> );
              >
              >Is it a good decision?
              >
              Any decision that moves you closer to your goal is good.
              >
              It could be an "it-works-but-you-should-never-do-this" solution :)
              >
              OK, I took another look and think that your solution does not really
              fall into that category. However, there is something to be said, of
              course. 'T1c' is a typedef in the header you didn't (or couldn't)
              include. Why is it a typedef? At some point the decision was made
              to have a typedef instead of forcing the user type 'T1<char>'. Was
              that to save typing or was there other reason? If it was to save
              typing, replacing 'T1c' with 'T1<char>' in the declaration above is
              perfectly OK. However, if it was because on some systems 'T1c' can
              be something else (and not necessarily 'T1<char>'), and the choice
              has to be governed by some #define or whatever other means, then
              being explicit here may not be what you need. The latter case is,
              admittedly, unlikely.
              >
              V
              --
              Please remove capital 'A's when replying by e-mail
              I do not respond to top-posted replies, please don't ask

              Comment

              Working...