Function pointer

This is a discussion on Function pointer within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by matsp And I'm all for a nice screen-layout, including correct use of clrscr() and similar functions - ...

  1. #16
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by matsp View Post
    And I'm all for a nice screen-layout, including correct use of clrscr() and similar functions - however, if you do that, you will have to use system specific functionality.
    Mats
    system("cls") ... ? Or you mean clear screen functions which will adapt to all systems which the program will run ... How possible is that?

  2. #17
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by csonx_p View Post
    system("cls") ... ? Or you mean clear screen functions which will adapt to all systems which the program will run ... How possible is that?
    There is (on ALMOST all systems) a way to clear the screen from inside an application - calling system is DEFINITELY one of the worst possible solutions from all aspects except independence of the compiler specifics.

    There was a post in the other thread about how you do it on Windows. For Linux, there are different solutions.

    You may also want to look into curses (dpcurses for example), which is a portable [as in, it implements a bunch of different sets of functions that are system dependant, and when building the library, chooses the one that is correct for the particular system].

    If you don't use curses, and what portability, you will need to use a similar mechanism - often you'd have a "windows_screenfuncs.cpp" and "linux_screenfuncs.cpp" or some such. Both of these will have the system specific functions that you need, such as clrscr() implemented - the implementation being different of course.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #18
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by matsp View Post
    There is (on ALMOST all systems) a way to clear the screen from inside an application - calling system is DEFINITELY one of the worst possible solutions from all aspects except independence of the compiler specifics.

    There was a post in the other thread about how you do it on Windows. For Linux, there are different solutions.

    You may also want to look into curses (dpcurses for example), which is a portable [as in, it implements a bunch of different sets of functions that are system dependant, and when building the library, chooses the one that is correct for the particular system].

    If you don't use curses, and what portability, you will need to use a similar mechanism - often you'd have a "windows_screenfuncs.cpp" and "linux_screenfuncs.cpp" or some such. Both of these will have the system specific functions that you need, such as clrscr() implemented - the implementation being different of course.

    --
    Mats
    Downloaded pdcurses, just by including <curses.h>, i get strange compile warnings & errors...

    some here ..

    Code:
    warning C4005: 'MOUSE_MOVED' : macro redefinition  
    error C2059: syntax error : '('
    error C2039: 'usr_iter' : is not a member of 'std::vector<_Ty>'
    error C2668: 'std::vector<_Ty>::end' : ambiguous call to overloaded function
    etc...

  4. #19
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,263
    Quote Originally Posted by csonx_p View Post
    How useful are delegates over members function pointers?
    A delegate in the C# sense is a member function pointer. In C++ a delegate could mean several different things. The term "function object" or "functor" is more common in the C++ world.

    The advantage to a functor is that it can carry additional information that helps to make the call. A method pointer is just a pointer to a function to call -- if that function takes any parameters (and it always takes at least one, the "this" pointer), these need to be stored somewhere so they can be passed when the function is called. That's what the functor takes care of.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #20
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    A delegate in the C# sense is a member function pointer.
    It's a bound function pointer - could be a member function bound to an object, or a free (or static member) function bound to nothing.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #21
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,263
    Quote Originally Posted by CornedBee View Post
    It's a bound function pointer - could be a member function bound to an object, or a free (or static member) function bound to nothing.
    I stand corrected.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 05:23 AM
  2. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  3. Function Pointer help
    By Skydt in forum C Programming
    Replies: 5
    Last Post: 12-02-2005, 09:13 AM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM

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