Embedded class' or VC++7 compiler's problem ?

Discussion in 'C++' started by N4M, Sep 28, 2004.

  1. N4M

    N4M Guest

    Dear,
    I have codes as follows:
    template<class T>
    class A {
    public: // embedded class
    class E;
    public: // types
    typedef E TE;
    public:// member functions
    TE somefunc();
    private: // member data
    //----------------------------
    // embedded class
    public:
    class E {
    //.....//
    };
    };
    //
    template<class T>
    A<T>::TE A<T>::somefunc() {....}

    When I compile these codes with VC++.NET, there are error messages:

    c:\DATA\C++\Common\list.h(389): error C2143: syntax error : missing
    ';' before 'list_base<TNValue>::insert'
    c:\DATA\C++\Common\list.h(389): error C2501:
    'list_base<TNValue>::iterator' : missing storage-class or type
    specifiers

    // TNValue = T, list_base = A, iterator = TE

    The same codes are compilled without problem by VC++ 6.

    How come?
    Is there something not-so-good with my embedded class use? Do you
    recommend embedded classes or have other better solutions?

    Thansk for your time.
    Nguyen Mai
    P/S: The same post can be found at .moderated/
    N4M, Sep 28, 2004
    #1
    1. Advertising

  2. N4M

    Howard Guest

    "N4M" <> wrote in message
    news:...
    > Dear,
    > I have codes as follows:
    > template<class T>
    > class A {
    > public: // embedded class
    > class E;
    > public: // types
    > typedef E TE;
    > public:// member functions
    > TE somefunc();
    > private: // member data
    > //----------------------------
    > // embedded class
    > public:
    > class E {
    > //.....//
    > };
    > };
    > //
    > template<class T>
    > A<T>::TE A<T>::somefunc() {....}
    >
    > When I compile these codes with VC++.NET, there are error messages:
    >
    > c:\DATA\C++\Common\list.h(389): error C2143: syntax error : missing
    > ';' before 'list_base<TNValue>::insert'
    > c:\DATA\C++\Common\list.h(389): error C2501:
    > 'list_base<TNValue>::iterator' : missing storage-class or type
    > specifiers
    >
    > // TNValue = T, list_base = A, iterator = TE
    >


    I don't see any "insert" anywhere there??? Perhaps you've snipped out the
    relevant code?

    Is there a reason you've substituted all the identifiers with these short
    names?

    Also, why are you using that typedef? You state at the bottom that TE is an
    iterator, but your typedef says it's the same as E. I'm confused, to say
    the least...

    -Howard
    Howard, Sep 28, 2004
    #2
    1. Advertising

  3. N4M

    N4M Guest

    "Howard" <> wrote in message news:<tmh6d.643028$>...
    > "N4M" <> wrote in message
    > news:...
    > > Dear,
    > > I have codes as follows:
    > > template<class T>
    > > class A {
    > > public: // embedded class
    > > class E;
    > > public: // types
    > > typedef E TE;
    > > public:// member functions
    > > TE somefunc();
    > > private: // member data
    > > //----------------------------
    > > // embedded class
    > > public:
    > > class E {
    > > //.....//
    > > };
    > > };
    > > //
    > > template<class T>
    > > A<T>::TE A<T>::somefunc() {....}
    > >
    > > When I compile these codes with VC++.NET, there are error messages:
    > >
    > > c:\DATA\C++\Common\list.h(389): error C2143: syntax error : missing
    > > ';' before 'list_base<TNValue>::insert'
    > > c:\DATA\C++\Common\list.h(389): error C2501:
    > > 'list_base<TNValue>::iterator' : missing storage-class or type
    > > specifiers
    > >
    > > // TNValue = T, list_base = A, iterator = TE
    > >

    >
    > I don't see any "insert" anywhere there??? Perhaps you've snipped out the
    > relevant code?
    >
    > Is there a reason you've substituted all the identifiers with these short
    > names?
    >
    > Also, why are you using that typedef? You state at the bottom that TE is an
    > iterator, but your typedef says it's the same as E. I'm confused, to say
    > the least...
    >
    > -Howard


    Thanks for your follow-up. The real code is somewhat lengthier, but
    the main point is:
    1- I use embedded classes (e.g. class E) and template for class A
    2- some functions are defined as:
    class A<T>::a type defined in A class A<T>::function declared in A()
    {....}
    //a function declared in A with a return type defined in A

    Then VC++.NET gives errors, while VC++.6 compiles. That's strange
    since VC++.NET is much more standard conformed (98% vs 86%). I have no
    other compilers to check.
    But I am unsure it is the good way to use embedded classes,
    especiallly along with template.
    Hope to receive your comments.
    Nguyen Mai
    N4M, Sep 28, 2004
    #3
  4. "N4M" <> wrote in message
    news:...
    > "Howard" <> wrote in message
    > news:<tmh6d.643028$>...
    >> "N4M" <> wrote in message
    >> news:...
    >> > Dear,
    >> > I have codes as follows:
    >> > template<class T>
    >> > class A {
    >> > public: // embedded class
    >> > class E;
    >> > public: // types
    >> > typedef E TE;
    >> > public:// member functions
    >> > TE somefunc();
    >> > private: // member data
    >> > //----------------------------
    >> > // embedded class
    >> > public:
    >> > class E {
    >> > //.....//
    >> > };
    >> > };
    >> > //
    >> > template<class T>
    >> > A<T>::TE A<T>::somefunc() {....}
    >> >
    >> > When I compile these codes with VC++.NET, there are error messages:
    >> >
    >> > c:\DATA\C++\Common\list.h(389): error C2143: syntax error : missing
    >> > ';' before 'list_base<TNValue>::insert'
    >> > c:\DATA\C++\Common\list.h(389): error C2501:
    >> > 'list_base<TNValue>::iterator' : missing storage-class or type
    >> > specifiers
    >> >
    >> > // TNValue = T, list_base = A, iterator = TE
    >> >

    >>
    >> I don't see any "insert" anywhere there??? Perhaps you've snipped out
    >> the
    >> relevant code?
    >>
    >> Is there a reason you've substituted all the identifiers with these short
    >> names?
    >>
    >> Also, why are you using that typedef? You state at the bottom that TE is
    >> an
    >> iterator, but your typedef says it's the same as E. I'm confused, to say
    >> the least...
    >>
    >> -Howard

    >
    > Thanks for your follow-up. The real code is somewhat lengthier, but
    > the main point is:
    > 1- I use embedded classes (e.g. class E) and template for class A
    > 2- some functions are defined as:
    > class A<T>::a type defined in A class A<T>::function declared in A()
    > {....}
    > //a function declared in A with a return type defined in A
    >
    > Then VC++.NET gives errors, while VC++.6 compiles. That's strange
    > since VC++.NET is much more standard conformed (98% vs 86%). I have no
    > other compilers to check.
    > But I am unsure it is the good way to use embedded classes,
    > especiallly along with template.
    > Hope to receive your comments.
    > Nguyen Mai


    I don't know why people expect their code errors to be fixed when they don't
    post the real code, or even compilable code.If your original code was too
    lengthy then surely you could have posted a complete example that
    illustrates the same problem?

    In any case with one minor addition and a few lines added for completeness
    your code compiles perfectly well on my copy of VC++ .NET

    template<class T>
    class A {
    public: // embedded class
    class E;
    public: // types
    typedef E TE;
    public:// member functions
    TE somefunc();
    private: // member data
    //----------------------------
    // embedded class
    public:
    class E {
    //.....//
    };
    };
    //
    template<class T>
    typename A<T>::TE A<T>::somefunc()
    {
    return A<T>::TE();
    }

    int main()
    {
    A<int> x;
    x.somefunc();
    }

    The minor addition was 'typename' which was missing from your somefunc()
    definition.

    If you want to check the correctness of your code then a good place to do so
    is here http://www.comeaucomputing.com/tryitout/. This online compiler also
    has no problem with your corrected code.

    john
    John Harrison, Sep 28, 2004
    #4
    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. E11
    Replies:
    1
    Views:
    4,684
    Thomas Weidenfeller
    Oct 12, 2005
  2. Colin Paul Gloster
    Replies:
    48
    Views:
    1,829
    Colin Paul Gloster
    Apr 10, 2007
  3. Thomas Dodds

    Databind an embedded control in an embedded datagrid

    Thomas Dodds, Jul 26, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    381
    Thomas Dodds
    Jul 26, 2004
  4. Trans
    Replies:
    11
    Views:
    277
    micathom
    Sep 5, 2007
  5. Num GG
    Replies:
    2
    Views:
    336
    Num GG
    Nov 17, 2008
Loading...

Share This Page