메시지가 표시된 후에 프로그램을 종료 할 가능성이 있으므로 오류 메시지를 표시하는 제네릭 함수를 만들려고합니다.함수의 C++ 매크로 및 기본 인수
원본 파일과 오류가 발생한 행을 표시하는 기능을 원합니다.
인수 목록 :
1.char *desc //description of the error
2.char *file_name //source file from which the function has been called
3.u_int line //line at which the function has been called
4.bool bexit=false //true if the program should exit after displaying the error
5.int code=0 //exit code
의 때문에 (4), (5) 내가 프로그램을 종료해야하지 않는 한 그들을 지정하지 않기 때문에, 함수 정의에 기본 인수를 사용해야합니다.
(2) 및 (3) 나 이와 같은 원시 함수로 리디렉션 매크로를 사용하는 것이 필요한 이유는
#define Error(desc, ???) _Error(desc,__FILE,__LINE__, ???)
문제 나 방법 그 2 개 요소를 참조하지 않는다는 것이다 함께 일해야합니다.
가 같이하는 방법의 예 : 당신은 C99에서 매크로를 오버로드 할 수 없습니다
if(!RegisterClassEx(&wndcls))
Error("Failed to register class",true,1); //displays the error and exits with exit code 1
if(!p)
Error("Invalid pointer"); //displays the error and continues
http://stackoverflow.com/questions/679979/how-to-make-a-variadic-macro-variable-number-of-arguments (어쩌면 http://stackoverflow.com/questions/10582500/c) -macro-and-default-arguments-in-function) – Vlad
__VA_ARGS__ 전에 '##'을 추가하면 실제로 variadic 매크로를 사용해 보았습니다. 그러나 ##이 없으면 작동하지 않았습니다. 덕분에 –
당신은 환영합니다 : -) – Vlad