varargs in .NET

Started by
4 comments, last by HappyDude 20 years ago
When Managed Extensions are in use, the compiler tells me I can''t use varargs: (warning C4793: native code generated for function ''Log::Error'': ''varargs not supported'') So, is there some new .NET equivalent?
Advertisement
I dunno, I just tried it and declaring a function:

void Test(int,...);

worked perfectly well for me. It didn''t complain at all.
I read your post, then set out to prove you wrong by writing a simple program proving my point. Of course, the program then went off and compiled, proving yours... goes to show, I should make sure I know exactly where the problem is before I ask about it...

That, however, doesn''t solve the problem . Reexamining code is currently in progress...
Oddly enough, I''ve found more ways to do it now that work than ways that don''t now that I''ve actually tried rearranging the code, so the problem doesn''t really matter anymore, I can get around it easily enough.

But, it is still a point of interest... so, here''s some code that generates the error:
#include <cstdarg>#include <cstdio>#include <string>using namespace std;class Useless{public:	void Bleh(int nLine,char *sFile,string sProps);	void Blah(char *sErr, ...);	};void Useless::Bleh(int nLine, char *sFile, string sProps){}void Useless::Blah(char *sErr, ...){		Bleh(0,"","Blah Blah");						va_list argList;		char sTemp[2048];		va_start(argList,sErr);		vsprintf(sTemp,sErr,argList);		va_end(argList);}


If I use a char* instead of string, it stops complaining. If the members are put within the class definition instead of after it, that also stops it from complaining... so as far as I can tell, there''s no reason for it to complain about this paticular layout - but it does.
Have you tried using something like params object[] obs in place of the ... , then just accessing those objects? It may help if you haven't.

EDIT:
NM, it's a C# keyword, there may be a managed c++ equivilant.



[edited by - cavemanbob on April 11, 2004 4:33:18 AM]
The ParamArray attribute should be what you are looking for:
Example:
	public __gc __interface IRenderable	{		void Render (IGE::IF_RenderDevice *ifRenderDev, IGE::HRENDERDEV renderDevHandle, [ParamArray]Object *args[]);	}; 


[edited by - VolkerG on April 11, 2004 5:08:54 AM]

This topic is closed to new replies.

Advertisement