473,811 Members | 3,467 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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<typena me 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 1220
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<typena me T, typename E>


template<templa te<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<typena me T, typename E>


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


Err...

template<templa te<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::allocat or<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::Contain erType& 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<typena me T, typename E>
template<templa te<class> T, typename E>


Err...

template<templa te<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::allocat or<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
1165
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 gcmodule.c, line 215 when compiling a script. Modules/gcmodule.c:215: failed asserrtion `gc->gc.gc_refs == GC_REACHABLE' This is maybe the third script I compile, so the python environment should still be very clean.
2
2509
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 to debug a python script? Thanks Alexander
15
2493
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 <netinet/in.h> #include <signal.h> #include <unistd.h>
2
1533
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
3694
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 timer to set the image of a label from an ImageList every 100ms or so. This is what was being used when I inherited this piece of code, and I thought it was OK, until I changed the size of the label to do animation on a larger piece of screen...
10
5162
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, umstring); Marshal::FreeHGlobal(IntPtr((void*)umstring)); I can't use StringToHGlobalAuto because it only ever returns the first character.
9
1937
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 Public Sub New(ByVal value As String)
8
6277
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 the following compiler error from Visual C++ 2005: error C2664: 'RasDialW' : cannot convert parameter 6 from 'cli::interior_ptr<Type>' to 'HRASCONN *'
11
2669
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
9605
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10386
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10133
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9204
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7669
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6889
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5554
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.