P
Protoman
#include <iostream>
#include <cstdlib>
#include <cmath>
#include "SmrtPtr.hpp"
using namespace std;
struct Data
{
double plus;
double mult;
double pow;
};
SmrtPtr<Data> math(const double& val,const double& val2);
int main()
{
for(;
{
cout << "Enter two values: " << endl;
double val, val2;
cin >> val >> val2;
SmrtPtr<Data> tuple=math(val,val2);
cout << tuple->plus << endl << tuple->mult << endl << tuple->pow <<
endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
SmrtPtr<Data> math(const double& val,const double& val2)
{
SmrtPtr<Data> tuple(new Data);
tuple->plus=val+val2;
tuple->mult=val*val2;
tuple->pow=pow(val,val2);
return tuple;
// should the d-tor get called here?!?
}
Here's the code for the class' d-tor:
~SmrtPtr<T>()
{
DataBase->sub();
if(DataBase->status()==0)
{delete ptr; delete DataBase; cout << "Deleted." << endl;}
else {delete DataBase; cout << "Out of scope. " << endl;}
}
}
#include <cstdlib>
#include <cmath>
#include "SmrtPtr.hpp"
using namespace std;
struct Data
{
double plus;
double mult;
double pow;
};
SmrtPtr<Data> math(const double& val,const double& val2);
int main()
{
for(;
{
cout << "Enter two values: " << endl;
double val, val2;
cin >> val >> val2;
SmrtPtr<Data> tuple=math(val,val2);
cout << tuple->plus << endl << tuple->mult << endl << tuple->pow <<
endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
SmrtPtr<Data> math(const double& val,const double& val2)
{
SmrtPtr<Data> tuple(new Data);
tuple->plus=val+val2;
tuple->mult=val*val2;
tuple->pow=pow(val,val2);
return tuple;
// should the d-tor get called here?!?
}
Here's the code for the class' d-tor:
~SmrtPtr<T>()
{
DataBase->sub();
if(DataBase->status()==0)
{delete ptr; delete DataBase; cout << "Deleted." << endl;}
else {delete DataBase; cout << "Out of scope. " << endl;}
}
}