Cant create curses's newwin() inside a class

This is a discussion on Cant create curses's newwin() inside a class within the Linux Programming forums, part of the Platform Specific Boards category; Hi every1. I am writing a console progy here using curses libraries. What i have here is a certain class ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    6

    Cant create curses's newwin() inside a class

    Hi every1. I am writing a console progy here using curses libraries. What i have here is a certain class which has 2 pointers of type WINDOW. In my general constructor i am calling newwin() so that it creates the windows and sets my pointers. However i am getting segmentaion fault for some reason. Can anyone help? Here is the code snippet:

    Code:
     
    class Base
    {
           private:
    	    WINDOW  *window;
    	    WINDOW  *win_temp;
           public:
    	    Base(int nlines,int ncols,int begin_y, int begin_x);
    };
    
    Base::Base(int nlines,int ncols,int begin_y, int begin_x)
    {
           window = newwin(nlines,ncols,begin_y,begin_x); 
     	
           if(window==NULL)
                 cout<<"window is NULL!"<<endl;
    
           win_temp = newwin(nlines,ncols,begin_y,begin_x);  //24,35,10,42
    
           if(win_temp==NULL)
                 cout<<"win_temp is NULL!"<<endl;
    
    }
    
    int main(void)
    {
          initscr();  /*  ncurses mode  */
          cbreak();	
          refresh();
          Base MyObject(24,35,10,2);
          endwin(); /* terminate ncurses mode */
          return 0;
    }
    If you are thinking that i am passing bogus values to newwin(), then it is not it. It works with those values when windows are created in main()

  2. #2
    xhi
    xhi is offline
    !anExpert
    Join Date
    Mar 2005
    Location
    pa
    Posts
    155
    just a guess.. but should initscr() (and/or the other ncurses functions that are currently in main) should they be inside Base's constructor where the window is created ?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 11-28-2008, 05:15 PM
  2. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 02:03 AM
  3. Threading from inside your class?
    By -KEN- in forum Windows Programming
    Replies: 3
    Last Post: 11-07-2003, 08:22 PM
  4. Templated functions inside a class
    By Stan100 in forum C++ Programming
    Replies: 3
    Last Post: 10-30-2003, 10:50 PM
  5. how do i define a const inside a class under private
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 11-01-2001, 06:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21