C
Chris Mabee
Hello all, and Merry Christmas,
I'm having a problem understanding an example of an array based
implementation of a stack in a textbook of mine. The code in question
is written below. The syntax is directly as in the book, except for
where I added the comments at the lines I wanted to refer to or to skip
sections of code.
template <class Element_Type>
class Stack
{
private:
// some variable declarations
Stack( const Stack & Value); // *1
public:
Stack(unsigned int Max_Size = 100);
const Stack & operator = ( const Stack & Value ); // *2
//destructor,push, and pop declarations
const Element_Type & Pop_And_Top();
const Element_Type & Top() const; // *3
//rest of declarations
};
The code at *1 and *2 is particularly troubling me. What I see at
*1 seems to be a call to the constructor using an unassigned stack
reference called Value. This makes no sense to me, so I'm assuming my
take on it is wrong. At *2 I see the same structure used to override
the assignment operator, but I'm really hazy on how this is working.
At *3 I don't know what the meaning of the extra 'const' at the end
of the line does. I was assuming that the functions were declared
'const Element_Type &' as references to an Element_Type, and were
constant because references can't be redefined. Again, feel free to
bust my bubble on this one. The extra 'const' through me for a loop.
The code for all of the functions is fairly straightforward. They
are all inline if it makes any difference. Thanks for any help.
Chris
BTW: This is my first post to this newsgroup so if it the format of the
message leaves something to be desired, let me know so my future posts
can be more effective. Thanks!
I'm having a problem understanding an example of an array based
implementation of a stack in a textbook of mine. The code in question
is written below. The syntax is directly as in the book, except for
where I added the comments at the lines I wanted to refer to or to skip
sections of code.
template <class Element_Type>
class Stack
{
private:
// some variable declarations
Stack( const Stack & Value); // *1
public:
Stack(unsigned int Max_Size = 100);
const Stack & operator = ( const Stack & Value ); // *2
//destructor,push, and pop declarations
const Element_Type & Pop_And_Top();
const Element_Type & Top() const; // *3
//rest of declarations
};
The code at *1 and *2 is particularly troubling me. What I see at
*1 seems to be a call to the constructor using an unassigned stack
reference called Value. This makes no sense to me, so I'm assuming my
take on it is wrong. At *2 I see the same structure used to override
the assignment operator, but I'm really hazy on how this is working.
At *3 I don't know what the meaning of the extra 'const' at the end
of the line does. I was assuming that the functions were declared
'const Element_Type &' as references to an Element_Type, and were
constant because references can't be redefined. Again, feel free to
bust my bubble on this one. The extra 'const' through me for a loop.
The code for all of the functions is fairly straightforward. They
are all inline if it makes any difference. Thanks for any help.
Chris
BTW: This is my first post to this newsgroup so if it the format of the
message leaves something to be desired, let me know so my future posts
can be more effective. Thanks!