Results 1 to 3 of 3

Thread: Simplify Function

  1. #1
    Join Date
    Jun 2011
    Posts
    203
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    7
    Thanked 4 Times in 3 Posts

    Default Simplify Function

    I'm trying to write a function with objects:

    Qt Code:
    1. void System::SetBetaParameter()
    2. {
    3. if(conditions)
    4. {
    5. cBetaOne.m_bState = ENGAGED;
    6. }
    7. else if(alternate conditions)
    8. {
    9. cBetaOne.m_bState = DISENGAGED;
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    My case is simple with just two conditions and two objects, so theoretically I can just write two if loops testing for type of object being tested, but this is very cumbersome and I'm more interested in doing it by passing by reference or as a pointer.

    Question that I have is, should I do the following:

    System.h
    Qt Code:
    1. #include "beta.h"
    2.  
    3. class System
    4. {
    5. Beta cBetaOne, cBetaTwo;
    6. Beta *cBetaOne, *cBetaTwo;
    7. }
    To copy to clipboard, switch view to plain text mode 

    Simply create the objects and then use their pointers after setting those pointers to correspond to those objects in the constructor or should I dynamically allocate those objects using new in the constructor and go from there?

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Wiki edits
    15

    Default Re: Simplify Function

    Youe question is not clear to me.

    Let me see, is your question about sould you create objects dynamically? Use dynamic allocation in situations where you don't know how many objects need to be created if at all they need to be created. If you know upfront that object has to be created and how many of those have to be created then go with static objects (global/stack based)
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Simplify Function

    What are the conditions?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. How to simplify a complex item delegate?
    By Adam Badura in forum Qt Programming
    Replies: 34
    Last Post: 23rd March 2013, 14:21
  2. pass member function as argument int template function
    By bibhukalyana in forum General Programming
    Replies: 1
    Last Post: 12th March 2013, 07:05
  3. Replies: 5
    Last Post: 25th February 2013, 16:37
  4. Replies: 11
    Last Post: 5th September 2012, 20:47
  5. Replies: 0
    Last Post: 10th March 2010, 08:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.