472,331 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,331 software developers and data experts.

STL, Handle-Body,templates

Hello!

Here I have two classes these are called Handle and Body and a main. You
have the class definition below.
Some basic information. In the Handle class is there a pointer to the Body.
Each Body object contains one primitive datatype int.
The Body instance is created in the constructor for Handle. In main I
instansiate some Handle object and use the STL function push_front to push
these object into the list.

But now to my question how do I do if I want to display the entire list
myList1 with all the ints that exist in each created body object. I want to
check that my push_front is doing what I expect it to do.
The only way to get the values from the Body class is to use the
functionoperator defines as
operator int() const
{ return this->value_; }

I think the solution is somewhat to write a function in the Handle class
that use the functionoperator.
The function in Handle as I think should use the STL function for_each in
some way.

Have you some good solution to my problem?

I know that I must add destructor, copy constuctor and assignment operator
and all that stuff.

Main
*******
include "handle.h"
#include <list>
#include <algorithm>
using namespace std;
int main()
{
list <Handle <Body> > myList1;

Handle<Body> myh1(1);
myList1.push_front(myh1);

Handle<Body> myh2(2);
myList1.push_front(myh2);

Handle<Body> myh3(3);
myList1.push_front(myh3);
return 0;
}

Handle
*******
#include "body.h"
#include <iostream>
using namespace std;
template<class t>
class Handle
{
public:
Handle(int value)
{ body = new Body(value); }
private:
Body *body;
};

Body
*****
#include <iostream>
class Body
{
public:
Body()
{}

Body(int value): value_(value)
{
copy_cnt = new int(0);
std::cout << "Creating original:"<< value << std::endl;
};

operator int() const
{ return this->value_; }

private:
int value_;
int *copy_cnt;
};

//Tony
Jul 23 '05 #1
0 2082

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Kong Li | last post by:
Follow up to this thread, the latest Oracle 9i release 2 patchset (9.2.0.5) fixed the handle count leak problem. The problem is in Oracle client...
3
by: Fred Hebert | last post by:
I am trying to use a 3rd party DLL that requires the main window handle as a parameter. e.g. MyFunc(WHND MyHandle); The example looks...
15
by: Tim Clacy | last post by:
Please illuminate; what operator of class 'Event' will get matched for these two cases : Event ev1; Event ev2; // Case 1 // if (ev1) ;
2
by: Indiana Epilepsy and Child Neurology | last post by:
Before asking this questions I've spent literally _years_ reading (Meyer, Stroustrup, Holub), googling, asking more general design questions, and...
14
by: Howard | last post by:
Hi, I recently had a problem where I decided to store objects in a vector. (Previously, I had always stored pointers in vectors). Well,...
6
by: Leandro Berti via DotNetMonster.com | last post by:
Hi All, I wrote a code to do serial communication with an equipament. When i use the code outside of threaded class it seens work properly, but...
7
by: Ken Varn | last post by:
I am working in managed C++. I have a Mutex object in which I need to replace the Handle property with a new handle. The new handle is being...
13
by: Abhishek | last post by:
Hi, how do I pass the handle of a control to the win32 api mouse_event. so that it will create the click event on that application only even if...
2
weaknessforcats
by: weaknessforcats | last post by:
Handle Classes Handle classes, also called Envelope or Cheshire Cat classes, are part of the Bridge design pattern. The objective of the Bridge...
3
by: Peterwkc | last post by:
Hello all C++ expert programmer, I have a handle class which point to another class and use the pointer as object. I follow the code from C++...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.