c++ - How to know if initscr() of ncurses has been called earlier? -


more of curiosity @ moment, there way know if initscr() of <ncurses.h> has been called before? believe calling initscr() twice bad idea.

you have bool variable that's initialized false , set true after calling initscr() (and performing other initializing). downside have remember check bool variable, , set after calling initscr().

there's straightforward example in link: http://math.hws.edu/orr/s04/cpsc225/curses.html

note: jonathon leffler points out in comments, link isn't great example overall, i'm pointing snippet of code initializes give example.

i'm not familiar library, looks declare window* , set null, , check see if it's null later see if it's been called. documentation found googling says on failure function doesn't return wouldn't have null pointer if it's run. that's in essence same using bool, maybe little less cluttered (and checking pointers see if they're null common c idiom).

a c++ way create class wraps window*, or whatever returned function, call initscr() in constructor. if there's corresponding function deallocate it, call in destructor. using a singleton design pattern, class can constructed once.

an safer way wrap window* in std::unique_ptr, pass custom deleter (how use custom deleter std::unique_ptr member?) - assuming there's function deallocates window.

then don't need in destructor, smart pointer deal you.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -