Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

memory leak problem 2

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
#include "DENOM.H"

Denomination::Denomination ( ) // default constructor
{
value=0;
count=0;
plural= NULL; // plural and sing are char pointers
sing= NULL;
}

Denomination::Denomination ( int d, char * s, char *m ) // Initialization constructor
{
value=d;
count=0;
sing=new.char[strlen(s)+1];
strcpy(sing,s);
if (!m)
plural= NULL;
else
plural=new.char[strlen(m)+1];
strcpy(plural,m);

}

Denomination::~Denomination () // Destructor
{
if (sing)
delete[] sing;
if (plural)
delete[] plural;
}

void Denomination::change ( long & amount )
{
count=value/amount;
amount%=value
}

void Denomination::print ()
{
if (count==1)
cout << count << sing;
else if (count>1)
cout << count << plural;

}
this is giving this error
a:\denom.h(2) : warning C4182: #include nesting level is 363 deep; possible infinite recursion
a:\denom.h(2) : fatal error C1076: compiler limit : internal heap limit reached; use /Zm to specify a higher limit
Error executing cl.exe.

please help this is due tomarrow!!!!!!!!!!!!!!
 
//a correct structure of a header file
////DENOM.H
#if !defined(__DEMON_H)//if is defined, will be not included
#define __DEMON_H

.....your declarations here


#endif John Fill
1c.bmp


ivfmd@mail.md
 
You didn't indicate what the name of this file is. I'm assuming that it is called denom.h and if so, denom.h is including itself. That will cause infinite recursion.

Incidentally, you've got a glitch in the initializing c'tor. The last line: strcpy(plural, m); should be inside braces following the else clause - you don't want to do a strcpy if plural is NULL.
 
For example I don't see here any problemsin code below. There will not be infinite recursion, against selfincluding.


//this is file denom.h
#if !defined(__DENOM_H)//if is defined, will be not included
#define __DENOM_H
#include&quot;denom.h&quot;
.....see your declarations here


#endif John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top