templates and managed code

  • Thread starter Thread starter Peter Oliphant
  • Start date Start date
P

Peter Oliphant

Is there any plan to support templates with managed code in the (near)
future? For instance, VS.NET 2005... : )
 
Peter said:
Is there any plan to support templates with managed code in the (near)
future? For instance, VS.NET 2005... : )

Templates have always (i.e. from the VS 2002 / 7.0 version) been
supported in managed code.

Templates on CLR types are supported starting with the VS 2005 / 8.0
versions.

Ronald Laeremans
Visual C++ team
 
template< int x >
class X {} ; // just fine

template< int y >
__gc classY{} ; //error C3151 '__gc' can't be applied to a template

What do you mean by 'templates have always been supported' if the simple
code above generates an error specifically saying you can't use '__gc' with
a template? [ I'm using the 2003 pro version of VC++.NET]

I guess I don't know what a CLR type is... : )
 
Peter said:
template< int x >
class X {} ; // just fine

template< int y >
__gc classY{} ; //error C3151 '__gc' can't be applied to a template

What do you mean by 'templates have always been supported' if the
simple code above generates an error specifically saying you can't
use '__gc' with a template? [ I'm using the 2003 pro version of
VC++.NET]
I guess I don't know what a CLR type is... : )

You can' declare managed template types, but you can use templates inside
Managed C++ code (in non-gc types).

Starting with VC2005 and CLI, you can use generics on managed types
(although not really as powerful as templates, generics are a first step in
the right direction).

Arnaud
MVP - VC
 
Managed templates are supported starting VC++ 2005 (and I believe it's only
for the new syntax).

VC++ 2003 did not support managed templates. But, what Ronald meant is that
your native templates would compile with /clr turned on - doesn't mean you
can have __gc template classes.

--
Regards,
Nish [VC++ MVP]


Peter Oliphant said:
template< int x >
class X {} ; // just fine

template< int y >
__gc classY{} ; //error C3151 '__gc' can't be applied to a template

What do you mean by 'templates have always been supported' if the simple
code above generates an error specifically saying you can't use '__gc'
with a template? [ I'm using the 2003 pro version of VC++.NET]

I guess I don't know what a CLR type is... : )


Ronald Laeremans said:
Templates have always (i.e. from the VS 2002 / 7.0 version) been
supported in managed code.

Templates on CLR types are supported starting with the VS 2005 / 8.0
versions.

Ronald Laeremans
Visual C++ team
 
Cool that it will be supported in 2005 (which will be released when? It's
close to needing a name change to 2006...lol)...

Will multiple-inheritance for managed (__gc) classes also be supported
perchance? In this case I would assume, if it's allowed at all, that when
creating a new managed multiple-inheritance class it would allow the use of
only *managed* base classes as parents...

Or is there a way to do managed multiple-inheritance now?

Nishant Sivakumar said:
Managed templates are supported starting VC++ 2005 (and I believe it's
only for the new syntax).

VC++ 2003 did not support managed templates. But, what Ronald meant is
that your native templates would compile with /clr turned on - doesn't
mean you can have __gc template classes.

--
Regards,
Nish [VC++ MVP]


Peter Oliphant said:
template< int x >
class X {} ; // just fine

template< int y >
__gc classY{} ; //error C3151 '__gc' can't be applied to a template

What do you mean by 'templates have always been supported' if the simple
code above generates an error specifically saying you can't use '__gc'
with a template? [ I'm using the 2003 pro version of VC++.NET]

I guess I don't know what a CLR type is... : )


Ronald Laeremans said:
Peter Oliphant wrote:
Is there any plan to support templates with managed code in the (near)
future? For instance, VS.NET 2005... : )

Templates have always (i.e. from the VS 2002 / 7.0 version) been
supported in managed code.

Templates on CLR types are supported starting with the VS 2005 / 8.0
versions.

Ronald Laeremans
Visual C++ team
 
Cool that it will be supported in 2005 (which will be released when? It's
close to needing a name change to 2006...lol)...

See:

http://lab.msdn.microsoft.com/vs2005/

The "Launch Tour" begins Nov 7, so I guess it'll all be available then.
Will multiple-inheritance for managed (__gc) classes also be supported
perchance? In this case I would assume, if it's allowed at all, that when
creating a new managed multiple-inheritance class it would allow the use of
only *managed* base classes as parents...

Or is there a way to do managed multiple-inheritance now?

The CLR allows a class to implement multiple interfaces, but it doesn't
support multiple inheritance of classes. The new C++/CLI language follows
the CLR WRT managed types.
 
Peter said:
Cool that it will be supported in 2005

Beware that managed generics are *NOT* templates, although the
(unfortunately IMHO) share most of their syntax. Mainly, generics do
not support specialization (partial or total), nor dependent types
definition/inference. On the other side, generics use a mechanism to
restrict what instanciations are authorized for a given "template".

Will multiple-inheritance for managed (__gc) classes also be supported
perchance?
Managed C++ allows only interface multiple-inheritance and class single
inheritance. Otherwise, it would be incompatible with other .NET
langages and the .NET CLR.

Or is there a way to do managed multiple-inheritance now?
You can multiple-inherits from interfaces. Implementation
multiple-inheritance, although sometimes invaluable, should bu used
only on rare occasions anyway (most of the time, using MI means that
you are using inheritance for something else than the Liskov
Substitution principle).

Arnaud
MVP - VC
 
Beware that managed generics are *NOT* templates, although the
(unfortunately IMHO) share most of their syntax. Mainly, generics do
not support specialization (partial or total), nor dependent types
definition/inference. On the other side, generics use a mechanism to
restrict what instanciations are authorized for a given "template".

I wasn't talking about generics - I was talking about managed templates
which support specialization, derivation from the template parameter type
etc.
 
Nishant said:
I wasn't talking about generics - I was talking about managed
templates which support specialization, derivation from the template
parameter type etc.

I know, but I was not sure that Peter Oliphant was aware of the difference.

Arnaud
MVP - VC
 
Hi Arnad,
I know, but I was not sure that Peter Oliphant was aware of the
difference.

I wasn't till now, so thanx for info! In fact, thanks to all who have
participated in this thread... : )

[==P==]
 
Back
Top