STL and Handle body pattern

T

Tony Johansson

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
 
L

Larry I Smith

Tony said:
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
 
T

Tony Johansson

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
 
L

Larry I Smith

Tony said:
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

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
 
T

Tony Johansson

Larry I Smith said:
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


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
 
K

Kai-Uwe Bux

Tony said:
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
 
L

Larry I Smith

Tony said:
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
 
M

Matthias Kaeppler

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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top