Results 1 to 3 of 3

Thread: default on class' public data

  1. #1
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default default on class' public data

    My class has a method that takes a class ( data class) as parameter and I want to put a default value if the caller won't supply it like
    Qt Code:
    1. class::function(int a = 3);
    To copy to clipboard, switch view to plain text mode 
    kinda thing.

    so here's what i did

    Qt Code:
    1. class A
    2. {
    3. public:
    4. class B
    5. {
    6. int x;
    7. };
    8. A()
    9. { defaultB.x = 3};
    10. run(B options = defaultB); // compiler complains about non-static defaultB which is correct
    11. private:
    12. B defaultB;
    13. };
    To copy to clipboard, switch view to plain text mode 

    do you guys know of any way that i can implement default on my methods passing a class ?

    baray98

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

    Default Re: default on class' public data

    Make defaultB a static object or construct defaultB inside the constructor or provide a constructor for B that will create defaultB and call that constructor as the default parameter for the method from A.

  3. The following user says thank you to wysota for this useful post:

    baray98 (29th July 2008)

  4. #3
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: default on class' public data

    I did the assigning of defaults in my constructor

    baray98

Similar Threads

  1. Replies: 5
    Last Post: 20th April 2008, 20:30
  2. class QHBoxLayout
    By csvivek in forum Installation and Deployment
    Replies: 2
    Last Post: 10th April 2008, 07:57
  3. default parameters in constructor class
    By mickey in forum General Programming
    Replies: 4
    Last Post: 23rd February 2008, 18:44
  4. Delayed Rendering of QTabWidget Tabs
    By mclark in forum Qt Tools
    Replies: 13
    Last Post: 14th May 2007, 22:53
  5. Link Errors
    By magikalpnoi in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2006, 22:04

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.