Like Tree3Likes

Try the free C++ GUI library for your hobby project.

This is a discussion on Try the free C++ GUI library for your hobby project. within the Projects and Job Recruitment forums, part of the Community Boards category; Originally Posted by cyberfish What if it has multiple functions? Classic OOP theory says objects should represent "things" with state ...

  1. #16
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    Quote Originally Posted by cyberfish View Post
    What if it has multiple functions?

    Classic OOP theory says objects should represent "things" with state (properties), and actions (methods).

    If something only does one thing, isn't it a function?
    It would have different functions...as a computer does.
    The () operator just represents the action : 'powering on'.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  2. #17
    Registered User
    Join Date
    Aug 2003
    Posts
    127
    Nana provides a template like std::function called nana::functor, the library uses this template for convenience and agility. For example.
    Code:
    void foo();
    
    struct T
    {
        void foo();
    };
    
    nana::functor<void()> fn;
    fn = foo;
    fn(); //call foo;
    
    T t;
    fn = nana::make_fun(t, &T::foo);
    fn(); // call t.foo();
    
    //it's convenient for event callback.
    
    button btn;
    btn.make_event<events::click>(foo);
    btn.make_event<events::click>(make_fun(t, &T::foo));
    Nana C++ Library is a GUI framework that designed to be C++ style, cross-platform and easy-to-use.

  3. #18
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,650
    Quote Originally Posted by manasij7479
    For example...if you have a class called Computer....its () operator could be appropriately used to start the computer ...
    That doesn't mean that the objects of that class are logically functions.
    Quote Originally Posted by manasij7479
    It would have different functions...as a computer does.
    The () operator just represents the action : 'powering on'.
    Its unary + operator could also be "appropriately" used to start the computer, and that doesn't mean that objects of that class are logically numeric in some way... once you begin abusing operator overloading, lots of strange names become appropriate

    The point is, a function object (functor) is logically a function. If you are overloading operator() for some other purpose, then you are not working with a function object, and we should start asking if the overloaded operator should have been given a more descriptive name, like... start.

    EDIT:
    In fact, overloading unary operator+ to start the computer is superior to overloading operator() because you can then overload unary operator- to mean shut down and operator~ to mean reboot!
    Last edited by laserlight; 12-12-2011 at 02:27 AM.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #19
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    Quote Originally Posted by laserlight View Post
    The point is, a function object (functor) is logically a function. If you are overloading operator() for some other purpose, then you are not working with a function object, and we should start asking if the overloaded operator should have been given a more descriptive name, like... start.
    But a device is also, logically a function; (...here, also having a state-machine as the back-end)
    You give a computer some inputs, (interactively or not)...and it produces an unique output...that is my justification for using the () to invoke it.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  5. #20
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,650
    Quote Originally Posted by manasij7479
    But a device is also, logically a function; (...here, also having a state-machine as the back-end)
    You give a computer some inputs, (interactively or not)...and it produces an unique output...that is my justification for using the () to invoke it.
    I don't exactly agree with you, but I must point out that you very nicely contradicted yourself
    Refer to:
    Quote Originally Posted by manasij7479
    For example...if you have a class called Computer....its () operator could be appropriately used to start the computer ...
    That doesn't mean that the objects of that class are logically functions.
    manasij7479 likes this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #21
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    Quote Originally Posted by laserlight View Post
    I don't exactly agree with you, but I must point out that you very nicely contradicted yourself
    Right..
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  7. #22
    Registered User
    Join Date
    Aug 2003
    Posts
    127
    Generally speaking, if we provide a framework and accept the exterior defined actions. like this.
    Code:
    template<typename Iterator, typename Functor>
    Functor for_each(Iterator beg, Iterator end, Functor fn)
    {
        for(Iterator i = beg; i != end; ++i)
            fn(*i);
        return fn;
    }
    In fact, we don't care whether fn is a function or function object, also don't care what fn does. And the user who calls for_each() should give a function or a object which can be applyed through function-call syntax.
    Nana C++ Library is a GUI framework that designed to be C++ style, cross-platform and easy-to-use.

  8. #23
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    The biggest difference between that and Qt's signals and slots system is that in S&S, the object generating the event doesn't need to explicitly call callbacks. The meta objects system does that for the programmer.

    All the programmer needs to do is bind slots to signals, and then, when the signal is fired, all connected slots will automatically be "called" (the observer pattern according to Wikipedia).

    It avoids having to write a callback functions that just calls a bunch of other callback functions. In the case of Qt, the "callback functions" (slots) can also be (and usually are) member functions, which makes designs simpler.

  9. #24
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    Quote Originally Posted by cyberfish View Post
    The biggest difference between that and Qt's signals and slots system is that in S&S, the object generating the event doesn't need to explicitly call callbacks. The meta objects system does that for the programmer.

    All the programmer needs to do is bind slots to signals, and then, when the signal is fired, all connected slots will automatically be "called" (the observer pattern according to Wikipedia).

    It avoids having to write a callback functions that just calls a bunch of other callback functions. In the case of Qt, the "callback functions" (slots) can also be (and usually are) member functions, which makes designs simpler.
    My point was that, you could design it in a way such that you do not have to resort to macros....moc...or whatever that changes the source.

    AFAI see, that is done in the library discussed here....in the OP.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  10. #25
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    That's true.

    I'm just trying to justify the use of moc in Qt (because I'm a big fan of it).

    This library also claims to make programming more intuitive and OO by not using macros, etc. But Qt says it uses moc exactly to make it more OO and intuitive.

    So the discussion now is on whether the library discussed here has achieved the goal.

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

Similar Threads

  1. Paid project - The Free Marketing Project
    By sharefree in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 10-27-2010, 02:15 PM
  2. new license-free lock-free data structure library published
    By Toby Douglass in forum Projects and Job Recruitment
    Replies: 19
    Last Post: 12-22-2009, 01:33 AM
  3. Looking for a hobby? We need everyone we can get!
    By zirgon in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 03-22-2008, 01:06 PM
  4. my free c++ library
    By jinhao in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 11-01-2007, 10:00 PM
  5. A free TIFF to PDF library
    By rockytriton in forum C++ Programming
    Replies: 0
    Last Post: 01-06-2006, 02:22 PM

Tags for this Thread


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