Thread View: csu.cs.200
4 messages
4 total messages
Started by Adam Carheden
Wed, 21 Oct 1998 00:00
Extend_STK()
Author: Adam Carheden
Date: Wed, 21 Oct 1998 00:00
Date: Wed, 21 Oct 1998 00:00
17 lines
1237 bytes
1237 bytes
I can't get my Stack.h ADT to compile. The problem is in the Extend_STK function that uses both the copy constructor and assignment operator (=) with &this as the argument. The compiler gives the error non-lvalue. I used the copy constructor to make a new stack of greater size and the assignment operator to set the old stack (this) to the new stack. Yes, I've tried compiling without this (as opposed to &this), but then I get a type error. The copy constructor and assignment operator both take Stack<...>& as arguments as shown in class. I think I'm totally on the wrong track with the whole Extend_STK function. Any hints (not code of course, rules are rules) would be appreciated. TIA -- Adam carheden@holly.colostate.edu
Re: Extend_STK()
Author: x1e1r1
Date: Thu, 22 Oct 1998 00:00
Date: Thu, 22 Oct 1998 00:00
36 lines
1898 bytes
1898 bytes
Adam Carheden wrote in message <362EC559.7273D88A@holly.colostate.edu>...
>I can't get my Stack.h ADT to compile. The problem is in the Extend_STK
>function that uses both the copy constructor and assignment operator (=)
>with &this as the argument. The compiler gives the error non-lvalue.
>I used the copy constructor to make a new stack of greater size and the
>assignment operator to set the old stack (this) to the new stack.
>
Have Extend_STK create a larger stack in the body of the function, without
making any
other calls. Then just assign the variables their proper values( e.g.
Stackptr). I didn't
have Extend_STK use the copy constructor or the assignment operator in its
body, and
it worked fine. I believe the copy constructor should just be used mainly
to instantiate
a second stack from main (Stack<..,..,..> S1; Stack<..,..,..> S2(S1); as
an example).
Feel free to email back if you have other questions
Josh Thomas
x1e1r1@concentric.net
>Yes, I've tried compiling without this (as opposed to &this), but then I
>get a type error. The copy constructor and assignment operator both
>take Stack<...>& as arguments as shown in class.
>
>I think I'm totally on the wrong track with the whole Extend_STK
>function. Any hints (not code of course, rules are rules) would be
>appreciated.
>TIA
>--
>Adam
>carheden@holly.colostate.edu
Re: Extend_STK()
Author: Chris Carlson
Date: Thu, 22 Oct 1998 00:00
Date: Thu, 22 Oct 1998 00:00
27 lines
1764 bytes
1764 bytes
Try writing the Extend_STK function without the copy constructor and assignment operator. Basically, what I did was copy the stack to a temporary stack, extend the origonal stack by the extend size, and then copy the temporary stack to the extended stack. Also, make sure you update the maximum stack size. Hope this helps. Chris Carlson Adam Carheden wrote: > > I can't get my Stack.h ADT to compile. The problem is in the Extend_STK > function that uses both the copy constructor and assignment operator (=) > with &this as the argument. The compiler gives the error non-lvalue. > I used the copy constructor to make a new stack of greater size and the > assignment operator to set the old stack (this) to the new stack. > > Yes, I've tried compiling without this (as opposed to &this), but then I > get a type error. The copy constructor and assignment operator both > take Stack<...>& as arguments as shown in class. > > I think I'm totally on the wrong track with the whole Extend_STK > function. Any hints (not code of course, rules are rules) would be > appreciated. > TIA > -- > Adam > carheden@holly.colostate.edu
Re: Extend_STK()
Author: John Erickson
Date: Thu, 22 Oct 1998 00:00
Date: Thu, 22 Oct 1998 00:00
19 lines
1586 bytes
1586 bytes
Wouldn't it make more sense to just create the new extended stack, copy the current one to that and update your pointers? This means there is only one copy operation and a fair amount less code. Chris Carlson wrote: > > Try writing the Extend_STK function without the copy constructor and > assignment operator. Basically, what I did was copy the stack to a > temporary stack, extend the origonal stack by the extend size, and then > copy the temporary stack to the extended stack. Also, make sure you > update the maximum stack size. Hope this helps. -- -==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==- John Erickson jerickso@holly.colostate.edu Black Sands Consulting Computer Science Major If they can make penicillin out of moldy bread, they can sure make something out of you. -- Muhammad Ali -==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads