473,405 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Vector<E> -> E __gc[]

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;
}

Nov 17 '05 #1
3 1199
ra*************@gmail.com wrote:
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>


template<template<class> T, typename E>

-cd

Nov 17 '05 #2
Carl Daniel [VC++ MVP] wrote:
ra*************@gmail.com wrote:
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>


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
Nov 17 '05 #3
ben
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
Carl Daniel [VC++ MVP] wrote:
ra*************@gmail.com wrote:
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>
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

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: David Helgason | last post by:
I am embedding python on Mac OSX (jaguar + panther) using boost::python. It works like a treat, but when using a python framework with asserts compiled in, I sometimes get an assert from...
2
by: alexLIGO | last post by:
Hi, I got this error when trying to execute the following python command with in a C module: Py_BuildValue Do anyone have any idea what this error is about? And does anyone have any idea how...
15
by: kernel.lover | last post by:
Hello, i want to know to have multiple clients connects to same server program does following is correct code #include <sys/types.h> #include <sys/socket.h> #include <stdio.h> #include...
2
by: Andreas Mueller | last post by:
Hi All, the following Situation is going through my mind: class Xox { public Xox(){} public object Foo(){ return null; } }
8
by: Beam_Us_Up_Scotty | last post by:
Hello all, I am trying to write a "simple" animation using C#, and I've tried many things but nothing seems to work for me without leaking memory. Here's a very simple piece of code that uses a...
10
by: Bonj | last post by:
I use the following code to convert a managed string to an unmanaged one: _TCHAR error; const char* umstring = (const char*)Marshal::StringToHGlobalAnsi (merror).ToPointer(); _tcscpy(error,...
9
by: Michael D. Ober | last post by:
OK, I can't figure out a way to optimize the following VB 2005 code using StringBuilders: Public Const RecSize as Integer = 105 Private buffer As String Public Sub New() init End Sub...
8
by: =?Utf-8?B?V2hpdG5leSBLZXc=?= | last post by:
Hi there, I'm having a bit of trouble using an HRASCONN object as a class member variable inside my managed C++ class. When I call RasDial() and pass in the address of my HRASCONN object, I get...
11
by: Steven Woody | last post by:
long i = nnn; long j; double d; d = i; j = ( long )d; in this case, i == j ? thanks.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.