STL and Handle body pattern

Discussion in 'C++' started by Tony Johansson, May 14, 2005.

  1. Hello!!

    Assume I have a handle body pattern with classes called Handle and Body.

    In the Body class I store one int value for example 7 or some other integer
    value.
    In the Handle class I have a pointer to the Body class.

    If a want to create a STL container of List with the following
    declaration List <Handle <Body> > list
    The list contains nodes with handles that contains a pointer to Body.

    In the constructor of class Handle I create dynamically an object of class
    Body so I have a pointer to a created Body object in class Handle.
    So in main I instansiate an object of class Handle

    Can somebode give me a hint how do I write if I want to store this Handle
    object called handle in the STL created List called list. I have to use some
    STL operation or Algoritm.


    //Tony
     
    Tony Johansson, May 14, 2005
    #1
    1. Advertising

  2. Tony Johansson wrote:
    > Hello!!
    >
    > Assume I have a handle body pattern with classes called Handle and Body.
    >
    > In the Body class I store one int value for example 7 or some other integer
    > value.
    > In the Handle class I have a pointer to the Body class.
    >
    > If a want to create a STL container of List with the following
    > declaration List <Handle <Body> > list
    > The list contains nodes with handles that contains a pointer to Body.
    >
    > In the constructor of class Handle I create dynamically an object of class
    > Body so I have a pointer to a created Body object in class Handle.
    > So in main I instansiate an object of class Handle
    >
    > Can somebode give me a hint how do I write if I want to store this Handle
    > object called handle in the STL created List called list. I have to use some
    > STL operation or Algoritm.
    >
    >
    > //Tony
    >
    >


    Read the two web pages below. In the examples for
    'std::list<string>' in section 12.3.2 just replace
    'string' with your 'Handle' class to get a basic
    idea of what you must do.

    For example, change:

    std::list<string> mylist;

    to

    std::list< Handle< Body > > mylist;

    Note that classes to be used in STL
    containers must meet certain requirements (have a
    copy constructor, an operator<(), etc); see the
    docs for details.

    http://www.icce.rug.nl/documents/cplusplus/cplusplus12.html
    http://www.icce.rug.nl/documents/cplusplus/cplusplus17.html

    Regards,
    Larry

    --
    Anti-spam address, change each 'X' to '.' to reply directly.
     
    Larry I Smith, May 14, 2005
    #2
    1. Advertising

  3. Hello again!!

    Have you any idea why I can't declare in this way
    list <Handle<Body> > myList;

    I get the following compilation error,
    c:\Documents and Settings\Tony\kau\cplusplus\lab4_c++\start.cpp(10): error
    C2947: expecting '>' to terminate template-argument-list, found '<'

    c:\Documents and Settings\Tony\kau\cplusplus\lab4_c++\start.cpp(10): error
    C2059: syntax error : '>'

    c:\Documents and Settings\Tony\kau\cplusplus\lab4_c++\start.cpp(10): error
    C2143: syntax error : missing ';' before '>'

    //Tony



    "Larry I Smith" <> skrev i meddelandet
    news:Nlrhe.3970$x85.934@trnddc01...
    > Tony Johansson wrote:
    >> Hello!!
    >>
    >> Assume I have a handle body pattern with classes called Handle and Body.
    >>
    >> In the Body class I store one int value for example 7 or some other
    >> integer value.
    >> In the Handle class I have a pointer to the Body class.
    >>
    >> If a want to create a STL container of List with the following
    >> declaration List <Handle <Body> > list
    >> The list contains nodes with handles that contains a pointer to Body.
    >>
    >> In the constructor of class Handle I create dynamically an object of
    >> class Body so I have a pointer to a created Body object in class Handle.
    >> So in main I instansiate an object of class Handle
    >>
    >> Can somebode give me a hint how do I write if I want to store this Handle
    >> object called handle in the STL created List called list. I have to use
    >> some STL operation or Algoritm.
    >>
    >>
    >> //Tony

    >
    > Read the two web pages below. In the examples for
    > 'std::list<string>' in section 12.3.2 just replace
    > 'string' with your 'Handle' class to get a basic
    > idea of what you must do.
    >
    > For example, change:
    >
    > std::list<string> mylist;
    >
    > to
    >
    > std::list< Handle< Body > > mylist;
    >
    > Note that classes to be used in STL
    > containers must meet certain requirements (have a
    > copy constructor, an operator<(), etc); see the
    > docs for details.
    >
    > http://www.icce.rug.nl/documents/cplusplus/cplusplus12.html
    > http://www.icce.rug.nl/documents/cplusplus/cplusplus17.html
    >
    > Regards,
    > Larry
    >
    > --
    > Anti-spam address, change each 'X' to '.' to reply directly.
     
    Tony Johansson, May 14, 2005
    #3
  4. Tony Johansson wrote:
    > Hello again!!
    >
    > Have you any idea why I can't declare in this way
    > list <Handle<Body> > myList;
    >
    > I get the following compilation error,
    > c:\Documents and Settings\Tony\kau\cplusplus\lab4_c++\start.cpp(10): error
    > C2947: expecting '>' to terminate template-argument-list, found '<'
    >
    > c:\Documents and Settings\Tony\kau\cplusplus\lab4_c++\start.cpp(10): error
    > C2059: syntax error : '>'
    >
    > c:\Documents and Settings\Tony\kau\cplusplus\lab4_c++\start.cpp(10): error
    > C2143: syntax error : missing ';' before '>'
    >
    > //Tony
    >
    >
    >
    > "Larry I Smith" <> skrev i meddelandet
    > news:Nlrhe.3970$x85.934@trnddc01...
    >
    >>Tony Johansson wrote:
    >>
    >>>Hello!!
    >>>
    >>>Assume I have a handle body pattern with classes called Handle and Body.
    >>>
    >>>In the Body class I store one int value for example 7 or some other
    >>>integer value.
    >>>In the Handle class I have a pointer to the Body class.
    >>>
    >>>If a want to create a STL container of List with the following
    >>>declaration List <Handle <Body> > list
    >>>The list contains nodes with handles that contains a pointer to Body.
    >>>
    >>>In the constructor of class Handle I create dynamically an object of
    >>>class Body so I have a pointer to a created Body object in class Handle.
    >>>So in main I instansiate an object of class Handle
    >>>
    >>>Can somebode give me a hint how do I write if I want to store this Handle
    >>>object called handle in the STL created List called list. I have to use
    >>>some STL operation or Algoritm.
    >>>
    >>>
    >>>//Tony

    >>
    >>Read the two web pages below. In the examples for
    >>'std::list<string>' in section 12.3.2 just replace
    >>'string' with your 'Handle' class to get a basic
    >>idea of what you must do.
    >>
    >>For example, change:
    >>
    >> std::list<string> mylist;
    >>
    >>to
    >>
    >> std::list< Handle< Body > > mylist;
    >>
    >>Note that classes to be used in STL
    >>containers must meet certain requirements (have a
    >>copy constructor, an operator<(), etc); see the
    >>docs for details.
    >>
    >>http://www.icce.rug.nl/documents/cplusplus/cplusplus12.html
    >>http://www.icce.rug.nl/documents/cplusplus/cplusplus17.html
    >>
    >>Regards,
    >>Larry
    >>
    >>--
    >>Anti-spam address, change each 'X' to '.' to reply directly.

    >
    >
    >


    Please don't top-post.

    Post a minimal code example that produces the problem,
    including the minimal class def's for 'Handle' and 'Body'.

    What compiler are you using?

    Did you '#include<list>' ?

    Does 'std::list< Handle< Body > > myList;' fix the problem?

    Is 'Handle<Body>' defined prior to trying to use it in a 'list'?

    Is either 'Handle' or 'Body' a reserved word (or already defined) by
    your compiler, OS, or one of the libs in use?

    Regards,
    Larry

    --
    Anti-spam address, change each 'X' to '.' to reply directly.
     
    Larry I Smith, May 14, 2005
    #4
  5. "Larry I Smith" <> skrev i meddelandet
    news:rLrhe.427$pb1.371@trnddc08...
    > Tony Johansson wrote:
    >> Hello again!!
    >>
    >> Have you any idea why I can't declare in this way
    >> list <Handle<Body> > myList;
    >>
    >> I get the following compilation error,
    >> c:\Documents and Settings\Tony\kau\cplusplus\lab4_c++\start.cpp(10):
    >> error C2947: expecting '>' to terminate template-argument-list, found '<'
    >>
    >> c:\Documents and Settings\Tony\kau\cplusplus\lab4_c++\start.cpp(10):
    >> error C2059: syntax error : '>'
    >>
    >> c:\Documents and Settings\Tony\kau\cplusplus\lab4_c++\start.cpp(10):
    >> error C2143: syntax error : missing ';' before '>'
    >>
    >> //Tony
    >>
    >>
    >>
    >> "Larry I Smith" <> skrev i meddelandet
    >> news:Nlrhe.3970$x85.934@trnddc01...
    >>
    >>>Tony Johansson wrote:
    >>>
    >>>>Hello!!
    >>>>
    >>>>Assume I have a handle body pattern with classes called Handle and Body.
    >>>>
    >>>>In the Body class I store one int value for example 7 or some other
    >>>>integer value.
    >>>>In the Handle class I have a pointer to the Body class.
    >>>>
    >>>>If a want to create a STL container of List with the following
    >>>>declaration List <Handle <Body> > list
    >>>>The list contains nodes with handles that contains a pointer to Body.
    >>>>
    >>>>In the constructor of class Handle I create dynamically an object of
    >>>>class Body so I have a pointer to a created Body object in class Handle.
    >>>>So in main I instansiate an object of class Handle
    >>>>
    >>>>Can somebode give me a hint how do I write if I want to store this
    >>>>Handle object called handle in the STL created List called list. I have
    >>>>to use some STL operation or Algoritm.
    >>>>
    >>>>
    >>>>//Tony
    >>>
    >>>Read the two web pages below. In the examples for
    >>>'std::list<string>' in section 12.3.2 just replace
    >>>'string' with your 'Handle' class to get a basic
    >>>idea of what you must do.
    >>>
    >>>For example, change:
    >>>
    >>> std::list<string> mylist;
    >>>
    >>>to
    >>>
    >>> std::list< Handle< Body > > mylist;
    >>>
    >>>Note that classes to be used in STL
    >>>containers must meet certain requirements (have a
    >>>copy constructor, an operator<(), etc); see the
    >>>docs for details.
    >>>
    >>>http://www.icce.rug.nl/documents/cplusplus/cplusplus12.html
    >>>http://www.icce.rug.nl/documents/cplusplus/cplusplus17.html
    >>>
    >>>Regards,
    >>>Larry
    >>>
    >>>--
    >>>Anti-spam address, change each 'X' to '.' to reply directly.

    >>
    >>
    >>

    >
    > Please don't top-post.
    >
    > Post a minimal code example that produces the problem,
    > including the minimal class def's for 'Handle' and 'Body'.
    >
    > What compiler are you using?
    >
    > Did you '#include<list>' ?
    >
    > Does 'std::list< Handle< Body > > myList;' fix the problem?
    >
    > Is 'Handle<Body>' defined prior to trying to use it in a 'list'?
    >
    > Is either 'Handle' or 'Body' a reserved word (or already defined) by
    > your compiler, OS, or one of the libs in use?
    >
    > Regards,
    > Larry
    >
    > --
    > Anti-spam address, change each 'X' to '.' to reply directly.



    Hello again!

    Here is main with the declaration that cause the compile error.
    I use Visual studio .NET

    Have you any idea how the declaration statement should be defined.?
    #include "body.h"
    #include <list>
    using namespace std;

    int main()
    {
    list <Handle <Body> > myList;
    return 0;
    }

    //Tony
     
    Tony Johansson, May 14, 2005
    #5
  6. Tony Johansson

    Kai-Uwe Bux Guest

    Tony Johansson wrote:

    > Hello again!!
    >
    > Have you any idea why I can't declare in this way
    > list <Handle<Body> > myList;


    This "list" is "std::list" ?

    > I get the following compilation error,
    > c:\Documents and Settings\Tony\kau\cplusplus\lab4_c++\start.cpp(10): error
    > C2947: expecting '>' to terminate template-argument-list, found '<'
    >
    > c:\Documents and Settings\Tony\kau\cplusplus\lab4_c++\start.cpp(10): error
    > C2059: syntax error : '>'
    >
    > c:\Documents and Settings\Tony\kau\cplusplus\lab4_c++\start.cpp(10): error
    > C2143: syntax error : missing ';' before '>'
    >

    [snip]

    a) Please do not top post.

    b) Please delete comments that you do not refer to.

    c) Show us your defintion of Handle. Are you sure it has been declared
    as a template?


    Best

    Kai-Uwe Bux
     
    Kai-Uwe Bux, May 14, 2005
    #6
  7. Tony Johansson wrote:
    > "Larry I Smith" <> skrev i meddelandet
    > news:rLrhe.427$pb1.371@trnddc08...
    >
    >>Tony Johansson wrote:
    >>
    >>>Hello again!!
    >>>
    >>>Have you any idea why I can't declare in this way
    >>>list <Handle<Body> > myList;
    >>>
    >>>I get the following compilation error,
    >>>c:\Documents and Settings\Tony\kau\cplusplus\lab4_c++\start.cpp(10):
    >>>error C2947: expecting '>' to terminate template-argument-list, found '<'
    >>>
    >>>c:\Documents and Settings\Tony\kau\cplusplus\lab4_c++\start.cpp(10):
    >>>error C2059: syntax error : '>'
    >>>
    >>>c:\Documents and Settings\Tony\kau\cplusplus\lab4_c++\start.cpp(10):
    >>>error C2143: syntax error : missing ';' before '>'
    >>>
    >>>//Tony
    >>>
    >>>
    >>>
    >>>"Larry I Smith" <> skrev i meddelandet
    >>>news:Nlrhe.3970$x85.934@trnddc01...
    >>>
    >>>
    >>>>Tony Johansson wrote:
    >>>>
    >>>>
    >>>>>Hello!!
    >>>>>
    >>>>>Assume I have a handle body pattern with classes called Handle and Body.
    >>>>>
    >>>>>In the Body class I store one int value for example 7 or some other
    >>>>>integer value.
    >>>>>In the Handle class I have a pointer to the Body class.
    >>>>>
    >>>>>If a want to create a STL container of List with the following
    >>>>>declaration List <Handle <Body> > list
    >>>>>The list contains nodes with handles that contains a pointer to Body.
    >>>>>
    >>>>>In the constructor of class Handle I create dynamically an object of
    >>>>>class Body so I have a pointer to a created Body object in class Handle.
    >>>>>So in main I instansiate an object of class Handle
    >>>>>
    >>>>>Can somebode give me a hint how do I write if I want to store this
    >>>>>Handle object called handle in the STL created List called list. I have
    >>>>>to use some STL operation or Algoritm.
    >>>>>
    >>>>>
    >>>>>//Tony
    >>>>
    >>>>Read the two web pages below. In the examples for
    >>>>'std::list<string>' in section 12.3.2 just replace
    >>>>'string' with your 'Handle' class to get a basic
    >>>>idea of what you must do.
    >>>>
    >>>>For example, change:
    >>>>
    >>>> std::list<string> mylist;
    >>>>
    >>>>to
    >>>>
    >>>> std::list< Handle< Body > > mylist;
    >>>>
    >>>>Note that classes to be used in STL
    >>>>containers must meet certain requirements (have a
    >>>>copy constructor, an operator<(), etc); see the
    >>>>docs for details.
    >>>>
    >>>>http://www.icce.rug.nl/documents/cplusplus/cplusplus12.html
    >>>>http://www.icce.rug.nl/documents/cplusplus/cplusplus17.html
    >>>>
    >>>>Regards,
    >>>>Larry
    >>>>
    >>>>--
    >>>>Anti-spam address, change each 'X' to '.' to reply directly.
    >>>
    >>>
    >>>

    >>Please don't top-post.
    >>
    >>Post a minimal code example that produces the problem,
    >>including the minimal class def's for 'Handle' and 'Body'.
    >>
    >>What compiler are you using?
    >>
    >>Did you '#include<list>' ?
    >>
    >>Does 'std::list< Handle< Body > > myList;' fix the problem?
    >>
    >>Is 'Handle<Body>' defined prior to trying to use it in a 'list'?
    >>
    >>Is either 'Handle' or 'Body' a reserved word (or already defined) by
    >>your compiler, OS, or one of the libs in use?
    >>
    >>Regards,
    >>Larry
    >>
    >>--
    >>Anti-spam address, change each 'X' to '.' to reply directly.

    >
    >
    >
    > Hello again!
    >
    > Here is main with the declaration that cause the compile error.
    > I use Visual studio .NET
    >
    > Have you any idea how the declaration statement should be defined.?
    > #include "body.h"
    > #include <list>
    > using namespace std;
    >
    > int main()
    > {
    > list <Handle <Body> > myList;
    > return 0;
    > }
    >
    > //Tony
    >
    >


    Please post the code for 'Handle' and 'Body'.
    Is it in 'body.h'? Without that code we can
    not tell you what might be wrong.

    Larry

    --
    Anti-spam address, change each 'X' to '.' to reply directly.
     
    Larry I Smith, May 14, 2005
    #7
  8. > Hello again!
    >
    > Here is main with the declaration that cause the compile error.
    > I use Visual studio .NET
    >
    > Have you any idea how the declaration statement should be defined.?
    > #include "body.h"
    > #include <list>
    > using namespace std;
    >
    > int main()
    > {
    > list <Handle <Body> > myList;
    > return 0;
    > }
    >
    > //Tony
    >
    >


    My bet:
    You're missing the definition of the Handle template, and this screws up
    the compiler because it doesn't know what Handle is, or differently put,
    it doesn't expect Handle to be a generic type and such expects a closing
    '>' after Handle.
    (Of course it doesn't matter whether or not Handle is a generic, if you
    don't provide its definition, it's an error).

    --
    Matthias Kaeppler
     
    Matthias Kaeppler, May 15, 2005
    #8
    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. Tony Johansson

    a piece of code for handle - body

    Tony Johansson, May 11, 2005, in forum: C++
    Replies:
    2
    Views:
    447
    Jonathan Mcdougall
    May 11, 2005
  2. Tony Johansson

    STL, Handle-Body,templates

    Tony Johansson, May 15, 2005, in forum: C++
    Replies:
    0
    Views:
    436
    Tony Johansson
    May 15, 2005
  3. Spam Catcher

    Custom SOAP Body... How to handle?

    Spam Catcher, Feb 5, 2008, in forum: ASP .Net Web Services
    Replies:
    3
    Views:
    234
    John Saunders [MVP]
    Feb 6, 2008
  4. London Boy
    Replies:
    2
    Views:
    356
    Keith Bowes
    Jan 12, 2004
  5. Replies:
    5
    Views:
    236
    A. Sinan Unur
    Sep 8, 2005
Loading...

Share This Page