Using Classes

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


Date: 28 Oct 2003 01:24:22 GMT

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

  • Using Classes
    ... Anyway, I have a program with two files, a header and a cpp main. ... header contains a class that handles a stack of ints (don't mind that I ... on template to the top of the class and changing int *top_ ... The compiler complains that a) parse ...
    (comp.lang.cpp)
  • [git patches] net driver updates for .26
    ... Fix a bug where the pointer never moves for dma_unmap... ... Update and fix driver debugging messages ... int reset); ... * header structure can be anywhere in the mcp. ...
    (Linux-Kernel)
  • Re: Having C code looking like C++ code
    ... providing an integer stack. ... | extern int push; ... | typedef struct stacktype { ... muck around inside the encapsulation to use the interface. ...
    (comp.lang.c)
  • Re: [OT] C programming, variable size array
    ... The trick to understanding here is to know how memory gets allocated. ... int main{ ... The stack holds "automatic" variables used in C, ... Will automatically allocate and deallocate 1K of data on the stack. ...
    (Debian-User)
  • Re: Link Instruction & tt command
    ... In order to do the trace, ... than C, the routine's entry point is non-standard, or the task's stack ... int f_c ... framepointer, and you can not make any stacktraces. ...
    (comp.os.vxworks)