473,386 Members | 1,720 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,386 software developers and data experts.

C# function with 'params' not working in managed C++?

Hi,

Maybe it's a known issue but i couldn't find any answer so far...

Consider this c# function:

// ----------------------------------
public int SumUp(params int[] iArgs)
{
int i = 0;
foreach (int iArg in iArgs)
i += iArg;
return i;
}
// ---------------------------------

So this function accepts variable number of arguments.
Now, i try to call it from a c++ project with 7 (for example) arguments and i get an error saying
that SumUp() doesn't expect 7 arguments. Basicly it doesn't work with any number of arguments...

I specifically created that helper c# project as i wanted to use functions with variable-number of
arguments in c++ and c++ (managed) itself doesn't support that. I tried v_list but it's not working
with managed c++.

Any solutions/workarounds?

I would really apreciate any ideas!
Thank you in advance,
Andrey
Nov 18 '05 #1
2 1591
Muzzy... I answered in the mc++ newsgroup: for the C# dll method:

namespace ClassLibrary1
{
public class Class1
{
public int TestArgs(params int[] args) {
return args.Length;
}
}
}

You can do in MC++2.0

int CallVarArgs() {
array<int,1>^ ai= gcnew array<int,1>(3){1,2,3};
ClassLibrary1::Class1^ c= gcnew ClassLibrary1::Class1;
return c->TestArgs(ai);
}

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Nov 18 '05 #2
Strange, my compiler has no trouble _now_ with handling varargs in
MC++2.0 aka C++/CLI.

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Nov 18 '05 #3

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

Similar topics

2
by: Tobias Olbort | last post by:
Hello, i've a outer function, which takes a params-array as a parameter. I want to pass this array to inner function with a params-array (e. g. string.format). When i've passed an integer to...
1
by: craigkenisston | last post by:
Hi, I'm trying to create a generic function to call stored procedures in a SQL Server database. I'm passing the params, values and the direction of the params in arrays. The function is...
5
by: MuZZy | last post by:
Hi, Maybe it's a known issue but i couldn't find any answer so far... Consider this c# function: // ---------------------------------- public int SumUp(params int iArgs) { int i = 0;
2
by: interX | last post by:
Hi, I have a little problem with managed/unmanaged in Visual Studio 2005 (Compiler setting /clr). I need to overhand several function pointers from managed to unmanaged. These function pointers...
3
by: =?Utf-8?B?SmFuIEhlcHBlbg==?= | last post by:
Hi, I've a question. I'm developing a windows application and for the application i need to run functions and procedures that are stored in a database. Here is an example that i tried to get...
7
by: malkarouri | last post by:
Hi everyone, I have written a function that runs functions in separate processes. I hope you can help me improving it, and I would like to submit it to the Python cookbook if its quality is good...
3
by: lawrence k | last post by:
One thing I like about Ruby is the use of symbols when passing function parameters to a function. One thing I dislike about PHP is that if a function has 4 optional parameters but you want to do...
4
by: lawrence k | last post by:
I'm working in PHP 4. Even if a parameter is mandatory, I nearly always give it a default value of "false". Then I print an error message if someone who is calling my function forgot the mandatory...
5
by: hurricane_number_one | last post by:
I'm trying to have a class, which uses threads be able to raise events to the form that created it. I've seen solutions around the net for this, but I didn't really like their implementation. ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.