I'm learning how to use ncurses, and wanted to use RAII to automatically init and end window:
class CWindow
{
public:
CWindow() {initscr();}
~CWindow() {endwin();}
};
This is basic idea of CWindow class. It works only for stdscr now, so using functions like addch(), printw(), etc. isn't a problem. However, this class will eventually be used to represent ncurses windows(WINDOW*). It would be intuitive to add member functions like print, so that instead of using
wprintw(win.getWin(), "str %i", someVar);
one could write
win.print("str %i", someVar);
I looked in web, but it seems to me that only cstdio's prinf and similar functions have been wrapped. And cstdio provides an easy way, with function that accepts va_list. However, ncurses doesn't have this set of functions.
To be honest, I'm rather using C++ then C, so my C knowledge isn't excellent. I've also not created any variable argument list functions. I tried naive approach:
void print(const char* str, ...)
{
va_list args;
va_start(args, str);
printw(str, args);
va_end(args);
}
However, it doesn't work. I also tried to incorporate variadic macros like in this thread, but it doesn't work for me. I may be doing it wrong though.
Anyway, how may I achieve this?