Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Student needs assistance... (deperately)

Reply
Thread Tools

Student needs assistance... (deperately)

 
 
sandy@murdocks.on.ca
Guest
Posts: n/a
 
      10-09-2006
I am a student with an assignement due tomorrow. I am to write a sort
of a memory manager, I don't want to go into all of the details (it's
long).

I have the following header file for my memory manager:
<code>
#ifndef MemManager_h
#define MemManager_h

#include <cstdlib>

class MemManager
{
public:
// Constructor
//
// Input : None
// Purpose: To create an empty MemManager
// Output : None

MemManager ( );


// Copy constructor
//
// Input : MemManager M
// Purpose: To initialize MemManager to M
// Output : None

MemManager ( const MemManager & M );

// Copy assignment
//
// Input : MemManager M
// Purpose: To assign Rhs to current MemManager
// Output : Current MemManager

const MemManager & operator= ( const MemManager & M );


// Destructor
//
// Input : None
// Purpose: To free memory of MemManager
// Output : None

~MemManager ( );


// Clear
//
// Input : None
// Purpose: To re-initialize MemManager to empty
// Output : None

void Clear ( );

//
// Input : None
// Purpose: To delete the top element of MemManager
// Output : 1 if successful; 0 otherwise
// Notes: Only used to clear the linked list for this class

int Pop ( );


// Empty
//
// Input : None
// Purpose: To check if MemManager is empty
// Output : 1 if empty; 0 otherwise

int Empty ( ) const;

/************************************************** ***
Allocate

Inputs: int Pages
Output: int Starting Page

Notes: Takes in the number of pages needed by a job
Outputs the starting page for the job in memory
returns -1 if there is not enough memory for the
job.
************************************************** *******/
int Allocate(int N);

/************************************************** ***********
GetNumPages

Inputs: None
Outputs: Pages

Notes: Returns the number of pages in the current
MemNode's block
type.
************************************************** ***********/
int GetNumPages(MemNode & MN);

/************************************************** ************
GetFirstPage

Inputs: None
Outputs: Page

Notes: Returns the first available memory page from the
current
MemNode's blockType.

************************************************** ******************/
//int GetFirstPage(MemNode & MN) const;



private:

typedef struct BlockType
{
int firstPage;
int numberPages;

//Constructor
BlockType() : firstPage(0), numberPages(59)
{}

//I am not sure that I should ALLOW this since we are
to be
// limited to 60 pages... I left it in...
BlockType(int f, int n) : firstPage(f), numberPages(n)
{}

}BlockType;

struct MemNode
{
BlockType Element;
MemNode *Next, *Previous;

// StackNode constructors
MemNode ( ) : Next ( NULL )
{}
MemNode ( const BlockType & E, MemNode *P = NULL ) :
Element ( E ), Next ( P )
{ }
};



// Pointer to the top of Stack
MemNode *Top;
int NumNodes;

};

#endif

</code>

In the private section I have a typedef (I know this C not C++ but I
cannot compile if I don't use the type def...)

I have a typedef of 'BlockType'. I am supposed to keep this Private
(requirement of the assignment) and I need to access the properties of
the BlockType: firstPage and numberPages (meaning the first available
page of memory and the number of pages available respectively.

I declare the following function:
int GetNumPages(MemNode & MN);

I get the non-sensical error of: expected `;' before '(' token

If I comment out the line the error goes away and it will compile. This
tells me there are no semi-colons missing on the lines above. The error
does not however point to any error that I can see to fix.

I am down to the crunch and I am stumped.

It would work fine (I think) if I moved the code into a seperate class
but the prof has specified that he does not want us to do that.

I however cannot figure out how to get access to those values. (Ant the
error does not help since the compiler is obviously confused.)

PLEASE HELP.

Thanks.

 
Reply With Quote
 
 
 
 
Gavin Deane
Guest
Posts: n/a
 
      10-09-2006

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I am a student with an assignement due tomorrow. I am to write a sort
> of a memory manager, I don't want to go into all of the details (it's
> long).
>
> I have the following header file for my memory manager:


I have trimmed out the comments fom your code to (hopefully) better
illustrate the problem.

> <code>
> #ifndef MemManager_h
> #define MemManager_h
>
> #include <cstdlib>
>
> class MemManager
> {
> public:
> MemManager ( );
> MemManager ( const MemManager & M );
> const MemManager & operator= ( const MemManager & M );
> ~MemManager ( );
> void Clear ( );
> int Pop ( );
> int Empty ( ) const;
> int Allocate(int N);


This is your problem line.
> int GetNumPages(MemNode & MN);
> private:
>
> typedef struct BlockType
> {


<snip>

> }BlockType;
>
> struct MemNode
> {


<snip>

> };
> MemNode *Top;
> int NumNodes;
> };
>
> #endif
>
> </code>


The compiler reads your code starting at the top and working towards
the bottom. When it reaches your problem line

int GetNumPages(MemNode & MN);

it's going to have trouble knowing what that means if it doesn't know
what MemNode is. And your definition of MemNode doesn't appear until
later.

Do you know about forward declarations? Alternatively, are you aware
that the public, protectected and private parts of a class do not need
to be declared in that order and that you can, for example, have a
private section followed by a public section followed by another
private section?

You said you got the error
expected `;' before '(' token

I don't know what compiler you are using, but Comeau online does a
better job of diagnosing the problem. It says
error: identifier "MemNode" is undefined

Sometimes compilers are like that. Making the intuitive link between
what the compiler says and what is actually wrong can be a bit of an
art.

<snip>

Gavin Deane

 
Reply With Quote
 
 
 
 
sandy@murdocks.on.ca
Guest
Posts: n/a
 
      10-09-2006
Thank you!

I have now got a private section, public section, private section.

I had no idea you could do that.

I don't know what forward declarations are, but they are now my list of
things to read about.

Thanks again.

FYI: It was recommended that I use Dev C++ by bloodshed so that is what
I use. That way I can hand in the whole project with the assignment and
they can either just run it, or complile it as they see fit.



Gavin Deane wrote:
> (E-Mail Removed) wrote:
> > I am a student with an assignement due tomorrow. I am to write a sort
> > of a memory manager, I don't want to go into all of the details (it's
> > long).
> >
> > I have the following header file for my memory manager:

>
> I have trimmed out the comments fom your code to (hopefully) better
> illustrate the problem.
>
> > <code>
> > #ifndef MemManager_h
> > #define MemManager_h
> >
> > #include <cstdlib>
> >
> > class MemManager
> > {
> > public:
> > MemManager ( );
> > MemManager ( const MemManager & M );
> > const MemManager & operator= ( const MemManager & M );
> > ~MemManager ( );
> > void Clear ( );
> > int Pop ( );
> > int Empty ( ) const;
> > int Allocate(int N);

>
> This is your problem line.
> > int GetNumPages(MemNode & MN);
> > private:
> >
> > typedef struct BlockType
> > {

>
> <snip>
>
> > }BlockType;
> >
> > struct MemNode
> > {

>
> <snip>
>
> > };
> > MemNode *Top;
> > int NumNodes;
> > };
> >
> > #endif
> >
> > </code>

>
> The compiler reads your code starting at the top and working towards
> the bottom. When it reaches your problem line
>
> int GetNumPages(MemNode & MN);
>
> it's going to have trouble knowing what that means if it doesn't know
> what MemNode is. And your definition of MemNode doesn't appear until
> later.
>
> Do you know about forward declarations? Alternatively, are you aware
> that the public, protectected and private parts of a class do not need
> to be declared in that order and that you can, for example, have a
> private section followed by a public section followed by another
> private section?
>
> You said you got the error
> expected `;' before '(' token
>
> I don't know what compiler you are using, but Comeau online does a
> better job of diagnosing the problem. It says
> error: identifier "MemNode" is undefined
>
> Sometimes compilers are like that. Making the intuitive link between
> what the compiler says and what is actually wrong can be a bit of an
> art.
>
> <snip>
>
> Gavin Deane


 
Reply With Quote
 
sandy@murdocks.on.ca
Guest
Posts: n/a
 
      10-09-2006
****

Sorry I spoke too soon.

It compiled because in my debugging I had commented out the function.

It didn't compile. I am still looking at the issue.


Gavin Deane wrote:
> (E-Mail Removed) wrote:
> > I am a student with an assignement due tomorrow. I am to write a sort
> > of a memory manager, I don't want to go into all of the details (it's
> > long).
> >
> > I have the following header file for my memory manager:

>
> I have trimmed out the comments fom your code to (hopefully) better
> illustrate the problem.
>
> > <code>
> > #ifndef MemManager_h
> > #define MemManager_h
> >
> > #include <cstdlib>
> >
> > class MemManager
> > {
> > public:
> > MemManager ( );
> > MemManager ( const MemManager & M );
> > const MemManager & operator= ( const MemManager & M );
> > ~MemManager ( );
> > void Clear ( );
> > int Pop ( );
> > int Empty ( ) const;
> > int Allocate(int N);

>
> This is your problem line.
> > int GetNumPages(MemNode & MN);
> > private:
> >
> > typedef struct BlockType
> > {

>
> <snip>
>
> > }BlockType;
> >
> > struct MemNode
> > {

>
> <snip>
>
> > };
> > MemNode *Top;
> > int NumNodes;
> > };
> >
> > #endif
> >
> > </code>

>
> The compiler reads your code starting at the top and working towards
> the bottom. When it reaches your problem line
>
> int GetNumPages(MemNode & MN);
>
> it's going to have trouble knowing what that means if it doesn't know
> what MemNode is. And your definition of MemNode doesn't appear until
> later.
>
> Do you know about forward declarations? Alternatively, are you aware
> that the public, protectected and private parts of a class do not need
> to be declared in that order and that you can, for example, have a
> private section followed by a public section followed by another
> private section?
>
> You said you got the error
> expected `;' before '(' token
>
> I don't know what compiler you are using, but Comeau online does a
> better job of diagnosing the problem. It says
> error: identifier "MemNode" is undefined
>
> Sometimes compilers are like that. Making the intuitive link between
> what the compiler says and what is actually wrong can be a bit of an
> art.
>
> <snip>
>
> Gavin Deane


 
Reply With Quote
 
sandy@murdocks.on.ca
Guest
Posts: n/a
 
      10-09-2006
Got it now.

Thanks again.


(E-Mail Removed) wrote:
> ****
>
> Sorry I spoke too soon.
>
> It compiled because in my debugging I had commented out the function.
>
> It didn't compile. I am still looking at the issue.
>
>
> Gavin Deane wrote:
> > (E-Mail Removed) wrote:
> > > I am a student with an assignement due tomorrow. I am to write a sort
> > > of a memory manager, I don't want to go into all of the details (it's
> > > long).
> > >
> > > I have the following header file for my memory manager:

> >
> > I have trimmed out the comments fom your code to (hopefully) better
> > illustrate the problem.
> >
> > > <code>
> > > #ifndef MemManager_h
> > > #define MemManager_h
> > >
> > > #include <cstdlib>
> > >
> > > class MemManager
> > > {
> > > public:
> > > MemManager ( );
> > > MemManager ( const MemManager & M );
> > > const MemManager & operator= ( const MemManager & M );
> > > ~MemManager ( );
> > > void Clear ( );
> > > int Pop ( );
> > > int Empty ( ) const;
> > > int Allocate(int N);

> >
> > This is your problem line.
> > > int GetNumPages(MemNode & MN);
> > > private:
> > >
> > > typedef struct BlockType
> > > {

> >
> > <snip>
> >
> > > }BlockType;
> > >
> > > struct MemNode
> > > {

> >
> > <snip>
> >
> > > };
> > > MemNode *Top;
> > > int NumNodes;
> > > };
> > >
> > > #endif
> > >
> > > </code>

> >
> > The compiler reads your code starting at the top and working towards
> > the bottom. When it reaches your problem line
> >
> > int GetNumPages(MemNode & MN);
> >
> > it's going to have trouble knowing what that means if it doesn't know
> > what MemNode is. And your definition of MemNode doesn't appear until
> > later.
> >
> > Do you know about forward declarations? Alternatively, are you aware
> > that the public, protectected and private parts of a class do not need
> > to be declared in that order and that you can, for example, have a
> > private section followed by a public section followed by another
> > private section?
> >
> > You said you got the error
> > expected `;' before '(' token
> >
> > I don't know what compiler you are using, but Comeau online does a
> > better job of diagnosing the problem. It says
> > error: identifier "MemNode" is undefined
> >
> > Sometimes compilers are like that. Making the intuitive link between
> > what the compiler says and what is actually wrong can be a bit of an
> > art.
> >
> > <snip>
> >
> > Gavin Deane


 
Reply With Quote
 
rexonf@gmail.com
Guest
Posts: n/a
 
      10-09-2006

(E-Mail Removed) wrote:
> ****
>
> Sorry I spoke too soon.
>
> It compiled because in my debugging I had commented out the function.
>
> It didn't compile. I am still looking at the issue.
>
>


Re-arrange your class, put the private section before the public
section.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Student needs a pair of eyes... Simple? problem sandy@murdocks.on.ca C++ 6 11-27-2006 12:49 AM
IPython team needs a student for a google "Summer of Code" project. Ville Vainio Python 0 05-03-2006 04:07 PM
Java Student Needs Help beyonder74 Java 5 09-15-2004 06:32 PM
A novice college student needs the help of the true "guru"s! Rodney Edmondson Java 3 11-25-2003 04:46 PM
Student needs help with CGI.pm (I think) Gary Schenk Perl Misc 6 09-25-2003 11:51 PM



Advertisments