a template question

Travis Spencer travislspencer@gmail.com
Sun Jul 24 03:17:00 GMT 2005


On 7/23/05, Nusret BALCI <balcinus@yahoo.com> wrote:
> I'm trying to compile the following code:

Where is the rest of it?  What do the _Environment_ and stack classes
look like?  Do they look something like this:

typedef int data_type;

template <typename T>
class stack
{
public:
    data_type *get_array(int);
};

template <typename T> class _Environment_
{
public:
    stack<T> *vstack, *stack;
};

Am I close?

> template <typename data_type, int stack_size>
> class Array
> {
>         public:
> static data_type* get_array(int length)
> {
>         if(!_Environment_<stack_size>::vstack)
>                 return
> _Environment_<stack_size>::stack->get_array<data_type>(length);
>         else
>                 return
> _Environment_<stack_size>::vstack->get_array<data_type>(length);
> }
> };

How do you instantiate Array objects?  Like this maybe:

Array<int, 10> a;

If so, then _Environment_ would look like this in the get_array method:

return _Environment_<10>::vstack->get_array<int>(length);

But `_Environment_<10>' doesn't make any sense.  The compiler wants a
type not a value.

> Unfortunately I have no access to a linux
> machine, therefore I'm stuck with MinGW

Linux is free you know ;-)

-- 

Regards,

Travis Spencer



More information about the Gcc-help mailing list