Re: Using Classes -- CLARIFICATIONS
From: Will Oram (spamguy_at_ihatespammers.com)
Date: 10/28/03
- Next message: VhD50: "C++ commands... Does anyone know?"
- Previous message: VhD50: "Re: integer to characters"
- In reply to: Will Oram: "Using Classes"
- Next in thread: David White: "Re: Using Classes"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
>
- Next message: VhD50: "C++ commands... Does anyone know?"
- Previous message: VhD50: "Re: integer to characters"
- In reply to: Will Oram: "Using Classes"
- Next in thread: David White: "Re: Using Classes"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|