Re: Using Classes -- CLARIFICATIONS

From: Will Oram (spamguy_at_ihatespammers.com)
Date: 10/28/03


Date: 28 Oct 2003 01:36:50 GMT

I realised I forgot a few things:
* I didn't just simplify the code for reading here...I commented out all
the excess stuff just to accomplish this basic task.
* I realise push()'s parameter would have to be converted to the Item
template as well as the other two changes I thought of. Still, because I
never use push(), it shouldn't impact the compiling.

Thanks.

In <20031027202422670-0500@news.cwru.edu> Will Oram wrote:
> Hi -- me again. This time, I swear I have an on-topic post. :)
> Again I apologise for any etiquette violations -- I don't use Usenet
> frequently, so I'm not terribly aware of the minute rules. Bear with
> me if I goof again.
>
> Anyway, I have a program with two files, a header and a cpp main. The
> header contains a class that handles a stack of ints (don't mind that
> I simplified it down to a few lines for ease of reading). This code
> builds fine.
>
> // MAIN FILE
>
> #include <iostream>
> #include "stack2.h"
>
> using namespace std;
>
> int main () {
> stack myStack;
> return 0;
>}
>
> // -----------
> // HEADER FILE
>
> // FILE: stack2.h
>
> #ifndef MAIN_SAVITCH_STACK2_H
> #define MAIN_SAVITCH_STACK2_H
>
> #include <cstdlib> // Provides NULL and size_t
> #include "node2.h"
>
> class stack {
> public:
> stack( ) { top_ptr = NULL; }
> void push(const int& entry);
> private:
> int top_ptr; // Points to top of stack
>} };
>
> #endif
>
> // END CODE
>
> However, I want to turn the above class into a template class. Tacking
> on template <class Item> to the top of the class and changing int *top_
> ptr to Item *top_ptr seems like it would be all that's necessary, but
> it doesn't compile when I do this. The compiler complains that a)
> parse error before ';', b) 'stack' is undeclared.
>
> What is wrong? Thanks.
>



Relevant Pages

  • Re: Using Classes -- CLARIFICATIONS
    ... I didn't just simplify the code for reading here...I commented out all ... it shouldn't impact the compiling. ... > stack myStack; ...
    (comp.lang.cpp)
  • Re: hardware errors, do C and Forth need different things in hardware?
    ... to the stack. ... After reading your other comments (hey, ... question backwards and so got the correct answer. ... M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html ...
    (comp.lang.forth)
  • RE: weird I/O problem with g77
    ... >I have come across a very strange problem whilst compiling a ... >The g77 compiler on both Cygwin and RH Linux systems produced the ... the ascii control character for linefeed) is taken as the ... it is not used in the value you are reading. ...
    (comp.lang.fortran)
  • Re: OT: Time team Channel 4 now
    ... I'm reading 'Engleby' by Faulks at the moment. ... That's next on my stack after Homage to Catalonia. ...
    (uk.rec.motorcycles)
  • RE: matching lines in array - other ways to code
    ... matching lines in array - other ways to code ... could somebody please suggest some other ways to simplify the reading ... and perhaps make the following process quicker? ...
    (perl.beginners)