M
ma740988
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
# 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