473,320 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

candidate for a reference counted smart pointer (?)


Consider:

# include <iostream>

using namespace std;

class algo;
class dpp;

class dpp {
algo* ptr_algo;
public:
void set( algo *ptr_algo_ )
{
ptr_algo = ptr_algo_;
}
void get_dpp_status() {}
void do_dpp_work();
void do_some_algo_stuff();
};

class algo {
dpp* ptr_dpp;
public:
void set( dpp *ptr_dpp_ )
{
ptr_dpp = ptr_dpp_;
// i think this is a call to operator= which means BEWARE (check the
books)
}
void algo_do_fft()
{
std::cout << " FFT done " << std::endl;
ptr_dpp->do_dpp_work(); /// tell dpp I'm done with FFT
}
void get_algo_status() {}
};

void dpp::do_dpp_work() {
std::cout << " I'm working " << std::endl;
}

void dpp::do_some_algo_stuff()
{
ptr_algo->algo_do_fft(); // tell algo to start FFT
}
// the exec is in charge of algo and dpp and will delete them
class exec {
algo* ptr_alg;
dpp* ptr_dpp;

public:
exec(dpp *ptr_dpp_, algo* ptr_alg_)
: ptr_alg(ptr_alg_)
, ptr_dpp(ptr_dpp_)
{
ptr_alg->set(ptr_dpp);
ptr_dpp->set(ptr_alg);
}
void get_status()
{
ptr_alg->get_algo_status();
ptr_dpp->get_dpp_status();
}
~exec() {
if (ptr_alg) delete ptr_alg; // exception here.
if (ptr_dpp) delete ptr_dpp;
}
};
int main()
{
algo g;
dpp d;
exec ex(&d, &g);

d.do_dpp_work();
d.do_some_algo_stuff();
}

My intent is to have the class exec 'owns' the resources. Similiarily,
I'd like for dpp and algo needs to 'access methods within each other'.
The destructor in exec generates execptions so something is amiss
hence I'm thinking perhaps a reference counted smart pointer will
suffice or ..... Could certainly use assistance on achieving my
objective.

Thanks in advance

Dec 12 '05 #1
0 843

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

Similar topics

0
by: Kalle Rutanen | last post by:
Hello I implemented reference counting in my program, and found out many problems associated with it. I wonder if the following problems can be solved automatically rather manually ? 1. ...
110
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object...
1
by: Tony Johansson | last post by:
Hello Experts! I reading a book called programming with design pattern revealed by Tomasz Muldner and here I read something that I don't understand completely. It says "A garbarage...
5
by: Matthias Kaeppler | last post by:
Hi, I was wondering, since STL containers are based around copying, whether it's a good idea to use reference counted smart pointers, such as boost::shared_ptr in STL containers. I can't store...
14
by: Alf P. Steinbach | last post by:
Not yet perfect, but: http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01.pdf http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01_examples.zip To access the table of...
1
by: oec.deepak | last post by:
Hi Cn any one telll me what is Reference counting in C++.
68
by: Jim Langston | last post by:
I remember there was a thread a while back that was talking about using the return value of a function as a reference where I had thought the reference would become invalidated because it was a...
5
by: Daniel Oberhoff | last post by:
Hi, Can someone more proficient in the details of the c++ type system please tell me how I can instantiate the for constesses of references that I think should be possible: 1. non-constant...
1
by: PeterAPIIT | last post by:
What is template template arguments and template typename arguments ? The reason i write in policy based design is because this is the requirement of the assignment. My code so far: ...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.