怎麼讓VC6.0支援可變引數巨集定義?
阿新 • • 發佈:2019-02-10
用不著過載()這樣就行:
#include <stdarg.h> //包含va_list
#include <stdio.h> //包含vsprintf()
#include <string.h>
#define MyPrtLog CPrtLogFunc(__FILE__,__LINE__).out
class CPrtLogFunc
{
public:
char * m_file;
int m_line;
CPrtLogFunc(char * file,int line)
{
m_file=file;
m_line=line;
}
void out(char * format,...)
{
printf("In file %s line %d",m_file,m_line);
va_list arg_ptr;
va_start(arg_ptr, format);
vprintf(format,arg_ptr);
va_end(arg_ptr);
}
};
void main()
{
MyPrtLog("Error%d\n","錯誤");
#include <stdarg.h> //包含va_list
#include <stdio.h> //包含vsprintf()
#include <string.h>
#define MyPrtLog CPrtLogFunc(__FILE__,__LINE__).out
class CPrtLogFunc
{
public:
char * m_file;
int m_line;
CPrtLogFunc(char * file,int line)
{
m_file=file;
m_line=line;
}
void out(char * format,...)
{
printf("In file %s line %d",m_file,m_line);
va_list arg_ptr;
va_start(arg_ptr, format);
vprintf(format,arg_ptr);
va_end(arg_ptr);
}
};
void main()
{
MyPrtLog("Error%d\n","錯誤");
}
轉自:https://bbs.csdn.net/topics/260007879