用不着重载()这样就行:
#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.youkuaiyun.com/topics/260007879