Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / March 2005

Tip: Looking for answers? Try searching our database.

Vector<E> -> E __gc[]

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ravenous.wolves@gmail.com - 02 Mar 2005 21:05 GMT
I'm trying to create a template function to convert from a vector of
Es, to a managed array of Es. I want this to work with std::vector, or
any other type that implements the call requirements of this function.

I get the following error on this code:
error C2143: syntax error : missing ')' before '<'

    template<typename T, typename E>
    E ToManaged( T<E> const & crUnmanagedVec ) __gc[]
    {
        int nElements = crUnmanagedVec.size();
        E managedArray __gc[] = new E __gc[nElements];

        for( int i = 0; i < nElements; ++i )
        {
            managedArray[i] = crUnmanagedVec[i];
        }

        return managedArray;
    }
Carl Daniel [VC++ MVP] - 02 Mar 2005 22:10 GMT
> I'm trying to create a template function to convert from a vector of
> Es, to a managed array of Es. I want this to work with std::vector, or
[quoted text clipped - 4 lines]
>
> template<typename T, typename E>

template<template<class> T, typename E>

-cd
Carl Daniel [VC++ MVP] - 02 Mar 2005 23:57 GMT
>> I'm trying to create a template function to convert from a vector of
>> Es, to a managed array of Es. I want this to work with std::vector,
[quoted text clipped - 5 lines]
>
> template<template<class> T, typename E>

Err...

template<template<typename> class T, typename E>

HOWEVER, that won't work for std::vector.  Sadly, the C++ standarization
committee made the regretable decision (IMO) to require template argument
lists for template template parameters to match exactly, rather than
requiring them to be compatible.

The template argument list for std::vector isn't simply <T>, rather, it's at
least <T,std::allocator<T> >.  More unfortunately, implementors are allowed
to add additional template parameters with defaults, so in practice it's
impossible to match a standard container such as std::vector to a template
template argument in a portable way.

-cd
ben - 03 Mar 2005 10:44 GMT
would this work?

template <typename E, typename Policy = DefPolicy<E> >
class CToManaged
{
public:

   E operator () (const typename Policy::ContainerType& crUnmanagedVec)
__gc[];
};

template <typename E>
class DefPolicy
{
public:
   typedef std::vector<E> ContainerType;
   //...
};

ben

> >> I'm trying to create a template function to convert from a vector of
> >> Es, to a managed array of Es. I want this to work with std::vector,
[quoted text clipped - 22 lines]
>
> -cd

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.