It looks an awful lot like you've just posted the assignment boilerplate code. How much work have you put into this yet?
Most of your class' functions are pretty basic. The constructor initializes things, the destructor probably doesn't need to do anything for this, isfull and isempty just compare the head and tail indices and respond accordingly, size is the difference in the indices, dump prints the contents of the array and the values of the indices, and put and get have to check if the state is valid then insert a value or remove one and adjust the indices accordingly.
Infarction
Posting Virtuoso
1,580 posts since May 2006
Reputation Points: 683
Solved Threads: 53
bool get(int &data); // always get the data of the current head
{
if (m_buffer == 0)
return false;
else
{
m_head *= data;
Is thisreally what you want to do? ;)
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
But what I want the boolean to do is get the data of the current head....so actually should i thought I could use a pointer so that the m_head* = the int data that is referenced in the boolean function.
You can't do it that way. Do you not see what's really going to happen? Since m_head is declared as an integer, what really happens is this:
m_head = m_head * data;
You're just multiplying the value in m_head against the value in data and storing this in m_head.
So I'm just guessing here, but when you call get() with an integer variable as a parameter, get() is supposed to set that to the value contained in m_head? In that case, a simple assignment would be all that's necessary:
data = m_head;
Since data is a reference, it the memory will remain in scope even after it returns.
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
For the constructor I was thinking of just leaving it as a default constructor, without definition, do you believe this would work? thanks!
Either you define the constructor or you don't declare it. Declaring something without defining it is going to cause a linker error.
What I'd probably do is something like have 1 constructor that has a default parameter, which if used by the programmer can add a node immediately after the object is initalized.
Your choice, but just decide whether or not to define and declare a constructor.
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
>I was thinking of simply using delete[]
Look closely at your code. Is there any place where you dynamically allocate memory? If so, then use it. If there is no dynamic memory allocation in your program (i.e. no new ), then you sure don't need (or rather shouldn't) deallocate memory.
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339