|
-
July 9th, 2010, 09:34 AM
#1
variable arguments of different data types
how to call a function with variable arguments of different data types
-
July 10th, 2010, 07:46 AM
#2
Re: variable arguments of different data types
-
July 10th, 2010, 09:00 AM
#3
Re: variable arguments of different data types
i have a function with variable arguments of different data types
eg: func(const1,int,const2,double,const3,string,NULL)
such func, i used va_list macros in native c++successfully using switch ... case, for conts1 assigning int, for const2 , double etc
but in managed c++ how do i
In sample programs i got know how to accept variable arguments only for integers not for mixed data types, so i want to know whether i can use va_list etc macros in managed c++, i tried using but it gives error like calling native code in managed
jalaja
-
July 10th, 2010, 10:30 PM
#4
Re: variable arguments of different data types
 Originally Posted by t.jalaja
i have a function with variable arguments of different data types
eg: func(const1,int,const2,double,const3,string,NULL)
such func, i used va_list macros in native c++successfully using switch ... case, for conts1 assigning int, for const2 , double etc
First of all, if one of your types was really "string" as in "std::string", then what you did is ill-formed and leads to undefined behaviour. It is invalid to pass non-POD type as a varying argument.
So just that alone means your "solution" (if what you posted is what you did), was no solution to begin with.
In sample programs i got know how to accept variable arguments only for integers not for mixed data types, so i want to know whether i can use va_list etc macros in managed c++, i tried using but it gives error like calling native code in managed
jalaja
I suggest you redesign your program to not do this, as pointed out, you can't pass non-POD types as varying parameters, regardless of what results you seem to have gotten with doing it in C++.
Regards,
Paul McKenzie
-
July 11th, 2010, 05:55 AM
#5
Re: variable arguments of different data types
Hello Sir
Thanks for ur reply
Can u please say how do i accept variable arguments for different data types in managed c++
for eg: func(...array<int>args) is for integers , in the same way how for strings, double, etc in the same function. If not able to understand my problem in specific, can u pl explain the variable arguments sample program other than for integers. Since theis topic is explained in many places for integers alone
waiting for an early response
regards
jalaja
-
July 11th, 2010, 09:38 AM
#6
Re: variable arguments of different data types
 Originally Posted by t.jalaja
Hello Sir
Thanks for ur reply
Can u please say how do i accept variable arguments for different data types in managed c++
First, explain on a high level what you're trying to achieve, instead of telling us what your "solution" is, and trying to make your solution work. Don't say "I'm passing varying arguments" -- explain what functionality you are attempting to achieve, not how you achieved it.
Second, C++ has templates. They are overloaded by type. If you need to do something generic, then write a template class/function, where the type is one of the template arguments.
Regards,
Paul McKenzie
-
July 11th, 2010, 09:59 AM
#7
Re: variable arguments of different data types
Thank u Sir
iam porting code from c++ to managed c++ .net. In my c++ i have a function named
func(const1, datatype1,const2,datatype2,and so on with variable arguments) declaration in header file in a class and implementation of this in cpp file (using macros from stdarg.h ) Thro application program iam calling the same func. But if i use macros from cstdarg in managed c++ .net, it gives a compilation error
hope iam clear this
regards
jalaja
-
July 11th, 2010, 10:05 AM
#8
Re: variable arguments of different data types
 Originally Posted by t.jalaja
Thank u Sir
iam porting code from c++ to managed c++ .net. In my c++ i have a function named
func(const1, datatype1,const2,datatype2,and so on with variable arguments) declaration in header file in a class and implementation of this in cpp file (using macros from stdarg.h )
I know this already, you've stated this three times now, and I understand. That is not what I'm asking you.
What I'm asking you is what is the purpose of this function? What is it trying to achieve?
Sometimes, you can't do line-by-line translations from one language to another. You have to understand exactly what the purpose of that function was, and if the other language doesn't have such a mechanism, rewrite that function using different techniques and paradigms.
Regards,
Paul McKenzie
-
July 11th, 2010, 11:57 PM
#9
Re: variable arguments of different data types
Use something like:
void func(array<Object^>^ parameters);
-
July 31st, 2010, 11:41 AM
#10
Re: variable arguments of different data types
Sorry for the delayed response
i tried using the array<Object>, so with this type iam able to pass integers, float, string, double (with appropriate tryParse)but if i pass struct, it gives compilation error of type difference,how do i typecast object to struct
regards
jalaja
-
August 12th, 2010, 01:45 AM
#11
Re: variable arguments of different data types
hi,
i have a function with variable arguments of different data types
eg: func(const1,int,const2,double,const3,string,NULL)
such func, i used va_list macros in native c++successfully using switch ... case, for conts1 assigning int, for const2 , double etc
regards,
phe9oxis,
http://www.guidebuddha.com
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|