forward declaration of a structure nested in a class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stephane Routelous

    forward declaration of a structure nested in a class

    Hi,

    I would like to make a forward declaration of a strcuture nested in a class.
    I have

    file A.h
    class A
    {
    public:
    struct B
    {
    };
    };

    file C.h
    class C
    {
    public:
    static doIt(const A::B& object);
    };

    I tried :
    struct A::B;
    but it doesn't work ( MSVCPP 6.0 last SP )

    Is it a way to do that ?

    thanks in advance,

    Stephane Routelous


  • John Carson

    #2
    Re: forward declaration of a structure nested in a class

    "Stephane Routelous" <nobody@nowhere .com> wrote in message
    news:c12rnn$kik $1@dns3.cae.ca[color=blue]
    > Hi,
    >
    > I would like to make a forward declaration of a strcuture nested in a
    > class. I have
    >
    > file A.h
    > class A
    > {
    > public:
    > struct B
    > {
    > };
    > };
    >
    > file C.h
    > class C
    > {
    > public:
    > static doIt(const A::B& object);
    > };
    >
    > I tried :
    > struct A::B;
    > but it doesn't work ( MSVCPP 6.0 last SP )
    >
    > Is it a way to do that ?
    >[/color]

    No, the only type of forward declaration allowed for a nested class is one
    inside the enclosing class, e.g.,

    class Outer
    {
    // forward declaration of inner class
    class Inner;
    // other stuff
    }

    // full declaration of inner class
    class Outer::Inner
    {
    // Inner stuff
    };


    --
    John Carson
    1. To reply to email address, remove donald
    2. Don't reply to email address (post here instead)

    Comment

    • Gianni Mariani

      #3
      Re: forward declaration of a structure nested in a class

      Stephane Routelous wrote:[color=blue]
      > Hi,
      >
      > I would like to make a forward declaration of a strcuture nested in a class.
      > I have
      >
      > file A.h
      > class A
      > {
      > public:
      > struct B
      > {
      > };
      > };
      >
      > file C.h
      > class C
      > {
      > public:
      > static doIt(const A::B& object);
      > };
      >
      > I tried :
      > struct A::B;
      > but it doesn't work ( MSVCPP 6.0 last SP )
      >
      > Is it a way to do that ?[/color]

      No.

      You might be able to use a template, i.e.:

      class A;

      class C
      {
      public:
      template <class tA>
      static int doIt(const typename tA::B & object);
      };


      class A
      {
      public:
      struct B
      {
      };
      };


      template <>
      int C::doIt<A>(cons t A::B & object)
      {
      }


      oops now I'm not sure you can specialize outside of the class
      declaration - this one is new to me.



      Comment

      • Gianni Mariani

        #4
        Re: forward declaration of a structure nested in a class

        Gianni Mariani wrote:[color=blue]
        > Stephane Routelous wrote:
        >[/color]

        .... Sorry I'd suggest you do it this way below - that way you don't need
        to specify the <A> in doit<A>.


        class A;

        class C
        {
        public:
        template <class tA_B>
        static int doIt(const tA_B & object);
        };


        class A
        {
        public:
        struct B
        {
        };
        };


        template <>
        int C::doIt<A::B>(c onst A::B & object)
        {
        return 0;
        }


        int main()
        {
        A::B x;

        C::doIt( x );
        }

        [color=blue]
        >
        > oops now I'm not sure you can specialize outside of the class
        > declaration - this one is new to me.
        >[/color]

        I'm still not sure this is legal but g++ (3.4prerel) works fine with it.

        Comment

        • Stephane Routelous

          #5
          Re: forward declaration of a structure nested in a class

          I tried that, but I got a beautiful internal compiler error with vc++6.0

          Thanks,

          Stephane

          "Gianni Mariani" <gi2nospam@mari ani.ws> wrote in message
          news:c12vi7$kkc @dispatch.conce ntric.net...[color=blue]
          > Gianni Mariani wrote:[color=green]
          > > Stephane Routelous wrote:
          > >[/color]
          >
          > ... Sorry I'd suggest you do it this way below - that way you don't need
          > to specify the <A> in doit<A>.
          >
          >
          > class A;
          >
          > class C
          > {
          > public:
          > template <class tA_B>
          > static int doIt(const tA_B & object);
          > };
          >
          >
          > class A
          > {
          > public:
          > struct B
          > {
          > };
          > };
          >
          >
          > template <>
          > int C::doIt<A::B>(c onst A::B & object)
          > {
          > return 0;
          > }
          >
          >
          > int main()
          > {
          > A::B x;
          >
          > C::doIt( x );
          > }
          >
          >[color=green]
          > >
          > > oops now I'm not sure you can specialize outside of the class
          > > declaration - this one is new to me.
          > >[/color]
          >
          > I'm still not sure this is legal but g++ (3.4prerel) works fine with it.
          >[/color]


          Comment

          • Gianni Mariani

            #6
            Re: forward declaration of a structure nested in a class

            Stephane Routelous wrote:[color=blue]
            > I tried that, but I got a beautiful internal compiler error with vc++6.0[/color]

            vc++6.0 is too old. Time to upgrade to GCC ... :-)


            Comment

            Working...