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

  1. #16
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    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'.

  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
    28,413
    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 03:27 AM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #19
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    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.

  5. #20
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #21
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    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..

  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,229
    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
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    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.

  10. #25
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    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.

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, 02: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, 03:22 PM

Tags for this Thread