i got a problem usin new operator when allocating desired number of rooms in a hotel manaement system
cin>>totrooms;
nofroom=new int[totrooms];
file.write((char*).......
please help me.
Printable View
i got a problem usin new operator when allocating desired number of rooms in a hotel manaement system
cin>>totrooms;
nofroom=new int[totrooms];
file.write((char*).......
please help me.
There isnt enough info here to help with anything....post more code
Well I don't know where you are stuck but are you doing something like this:
Code:class myClass {
void *operator new (size_t size) {
return malloc(size*sizeof(myClass));
}
};
What kind of problems are you having??
error, you are not getting the result you want or what?
U R trying to allocate memory for your # of rooms.Quote:
allocating desired number of rooms in a hotel manaement system
An example might be:
For discrete objects of type Blanks, the global operator new function is hidden. Therefore, the following code allocates an object of type Blanks and initializes it to 0xa5:Code:#include <malloc.h>
#include <memory.h>
class Blanks
{
public:
Blanks(){}
void *operator new( size_t stAllocateBlock, char chInit );
};
void *Blanks::operator new( size_t stAllocateBlock, char chInit )
{
void *pvTemp = malloc( stAllocateBlock );
if( pvTemp != 0 )
memset( pvTemp, chInit, stAllocateBlock );
return pvTemp;
}
The argument supplied in parentheses to new is passed to Blanks::operator new as the chInit argument. However, the global operator new function is hidden, causing code such as the following to generate an error:Code:int main()
{
Blanks *a5 = new( 0xa5 ) Blanks;
return a5 != 0;
}
Blanks *SomeBlanks = new Blanks;
Pls let me know if this helps!
;)
Disable Smilies in This Post by Salem