public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* a template question
@ 2005-07-23  7:22 Nusret BALCI
  2005-07-24  3:17 ` Travis Spencer
  0 siblings, 1 reply; 2+ messages in thread
From: Nusret BALCI @ 2005-07-23  7:22 UTC (permalink / raw)
  To: gcc-help


Hello all,
I'm trying to compile the following code:
///////////////////////////////////////////
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);
}
};
////////////////////////////////////////////////
Here _Environment_ is another template class.

The code compiles and works correctly under
MSVC.NET2003. But not under MinGW 3.4.4. 

The same code compiles without any problem if I remove
the wrapper class and define the function as a
standalone template function. Error is about the line

_Environment_<stack_size>::vstack->get_array<data_type>(length);

Error: Primary expression expected before >

However, this error doesn't show up in case of
template function, instead of a template class.

As I need to keep my code compilable under linux, as
well as under Windows, I would appreciate if someone
can tell me whether this behavior is the current state
of the art in GCC world (for compiler version 4.01 for
instance), or it's a past thing which affects 3.4.*
series. Unfortunately I have no access to a linux
machine, therefore I'm stuck with MinGW, and they
don't have the 4.01 series yet, even if it solves this
issue. Does it?

Or, what's wrong with this code, and why the same
thing works for template classes, but not for template
functions..

Best regards,

Nusret


		
____________________________________________________
Start your day with Yahoo! - make it your home page 
http://www.yahoo.com/r/hs 
 

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: a template question
  2005-07-23  7:22 a template question Nusret BALCI
@ 2005-07-24  3:17 ` Travis Spencer
  0 siblings, 0 replies; 2+ messages in thread
From: Travis Spencer @ 2005-07-24  3:17 UTC (permalink / raw)
  To: Nusret BALCI; +Cc: gcc-help

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-07-24  3:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-23  7:22 a template question Nusret BALCI
2005-07-24  3:17 ` Travis Spencer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).