There seems to be a problem with Assignment 3!


[ Follow Ups ] [ Post Followup ] [ CCNY CSc 212 Messages ] [ Help ]

Posted by Jorge Casanova on October 11, 2002 at 10:40:19:

Ok...so I impliminted everything that needs to be implimented using dynamic array...but...the non-interactive program...there is and error....

c:\program files\microsoft visual studio\myprojects\assignment 3\sequence2.cpp(81) : error C2821: first formal parameter to 'operator new' must be 'unsigned int'

and this is where it says....

const sequence::size_type BORDER_SIZE = 2*sizeof(double);
const char GARBAGE = 'g';
const char BORDER = 'b';
static sequence::size_type memory_used_now = 0;

void* operator new(sequence::size_type size)
{
char *whole_block; // Pointer to the entire block that we get from heap
sequence::size_type *size_spot; // Spot in the block where to store a copy of size
char *front_border; // The border bytes in front of the user's memory
char *middle; // The memory to be given to the calling program
char *back_border; // The border bytes at the back of the user's memory
sequence::size_type i; // Loop control variable

// Allocate the block of memory for the user and for the two borders.
whole_block = (char *) malloc(2*BORDER_SIZE + size);
if (whole_block == NULL)
{
cout << "Insufficient memory for a call to the new operator." << endl;
exit(0);
}

// Figure out the start points of the various pieces of the block.
size_spot = (sequence::size_type *) whole_block;
front_border = (char *) (whole_block + sizeof(sequence::size_type));
middle = (char *) (whole_block + BORDER_SIZE);
back_border = middle + size;

// Put a copy of the size at the start of the block.
*size_spot = size;

// Fill the borders and the middle section.
for (i = 0; i < BORDER_SIZE - sizeof(sequence::size_type); i++)
front_border[i] = BORDER;
for (i = 0; i < size; i++)
middle[i] = GARBAGE;
for (i = 0; i < BORDER_SIZE; i++)
back_border[i] = BORDER;

// Update the global static variable showing how much memory is now used.
memory_used_now += size;

return middle;
}

What do you think it is?...I can't continue because of this error...
Once again everything has been implimented and there are no errors...except the way the non-interactive .cpp was written...


Follow Ups:



Post a Followup

Name:
E-Mail:

Subject:

Comments:


[ Follow Ups ] [ Post Followup ] [ CCNY CSc 212 Messages ] [ Help ]