By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,505 Members | 1,206 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,505 IT Pros & Developers. It's quick & easy.

STL and Handle body pattern

P: n/a
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
Jul 23 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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/cpl...lusplus12.html
http://www.icce.rug.nl/documents/cpl...lusplus17.html

Regards,
Larry

--
Anti-spam address, change each 'X' to '.' to reply directly.
Jul 23 '05 #2

P: n/a
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" <la***********@verizon.net> 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/cpl...lusplus12.html
http://www.icce.rug.nl/documents/cpl...lusplus17.html

Regards,
Larry

--
Anti-spam address, change each 'X' to '.' to reply directly.

Jul 23 '05 #3

P: n/a
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" <la***********@verizon.net> 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/cpl...lusplus12.html
http://www.icce.rug.nl/documents/cpl...lusplus17.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.
Jul 23 '05 #4

P: n/a

"Larry I Smith" <la***********@verizon.net> 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" <la***********@verizon.net> 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/cpl...lusplus12.html
http://www.icce.rug.nl/documents/cpl...lusplus17.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
Jul 23 '05 #5

P: n/a
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
Jul 23 '05 #6

P: n/a
Tony Johansson wrote:
"Larry I Smith" <la***********@verizon.net> 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" <la***********@verizon.net> 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/cpl...lusplus12.html
http://www.icce.rug.nl/documents/cpl...lusplus17.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.
Jul 23 '05 #7

P: n/a
> 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
Jul 23 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.