Re: Leak or Crash. Don't understand why
On 6=E6=9C=8810=E6=97=A5, =E4=B8=8B=E5=8D=889=E6=99=8217=E5=88=86, Ulrich E=
ckhardt <eckha...@satorlaser.com> wrote:
Luk Jack wrote:
On 6=E6=9C=8810=E6=97=A5, =E4=B8=8B=E5=8D=887=E6=99=8209=E5=88=86, Ulri=
ch Eckhardt <eckha...@satorlaser.com> wrote:
1. Wrapping something into a class that only contains functions and no
actual state (which is what your cMath class looks like, though I'm no=
t
sure) is wrong. If you need, use a namespace instead. I guess you have
this habit and probably a few others from Java or similar languages th=
at
force you to use classes for everything.
[...]
Actually, I've got an attribute in my cMath class, so isn't it
stateless, is it? not too sure :)
Yes, that would be a valid reason to put it into a class.
Uli
--
C++ FAQ:http://parashift.com/c++-faq-lite
Sator Laser GmbH
Gesch=C3=A4ftsf=C3=BChrer: Thorsten F=C3=B6cking, Amtsgericht Hamburg HR =
B62 932
class cMath
{
public:
cMath() { }
~cMath() { }
double Integrate(const Formula& f);
void Derive(const Formula& f);
Terms *Solve_Term(const Terms& t);
double Power(double x, int p);
// Formula m_vNomralFunctions; // Normal Functions for generating
approx function
const Formula& getFormula() { return m_vFormula; }
private:
Formula m_vFormula;
};
inline void cMath::Derive(const Formula& f)
{
Terms *t1 = new Terms();
for (unsigned int i = 0; i < f.size(); i++)
{
t1 = Solve_Term(f[i]);
m_vFormula.push_back(*t1);
}
delete t1;
}
inline Terms *cMath::Solve_Term(const Terms& t)
{
Terms *t1 = new Terms();
t1->coefficient = t.coefficient;
t1->degree = t.degree-1;
t1->coefficient = t1->coefficient*t.degree;
if (t1->degree < 0)
t1->coefficient = 0;
//delete t1;
return t1;
}
Thanks