Results 1 to 3 of 3

Thread: how to declare a variable as polymorphic?

  1. #1
    Join Date
    Nov 2009
    Posts
    94
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question how to declare a variable as polymorphic?

    Hello,

    I would like to assign a data type to a variable first during the execution, but not at the beginning yet. How should then I declare such a variable first?

    Below is my code, where I want to use it:

    Qt Code:
    1. polymorphic Data type *net;
    2. polymorphic Data type *netMin;
    3.  
    4. switch(which_network){
    5. case 0: // Linear Output Feed Forward Network was chosen
    6. net = new LinOutFFNet(input, output, connectionMatrix);
    7. netMin = new LinOutFFNet(input, output, connectionMatrix);
    8.  
    9. break;
    10. case 1: // Feed Forward Network was chosen
    11. net = new FFNet(input, output, connectionMatrix);
    12. netMin = new FFNet(input, output, connectionMatrix);
    13.  
    14. break;
    15. case 2: // radial basis function network was chosen
    16. net = new RBFNet(input, output, connectionMatrix);
    17. netMin= new RBFNet(input, output, connectionMatrix);
    18.  
    19. break;
    20. }
    To copy to clipboard, switch view to plain text mode 

    Thank you

    best regards,

    Vitali
    Last edited by rambo83; 17th December 2009 at 11:47.

  2. #2
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to declare a variable as polymorphic?

    I guess you need to go back to OOP basics... All you need is to have a base class, possibly pure virtual (i.e abstract, an interface, ...), for instance AbstractNet, which would define the base API of all network classes (e.g read(), write(), ...) and all other classes would inherit from that base class and reimplement the proper methods.

    Then "declaring a variable as polymorphic" boils down to declaring it as a pointer to an object of the base class.
    Current Qt projects : QCodeEdit, RotiDeCode

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

    rambo83 (17th December 2009)

  4. #3
    Join Date
    Nov 2009
    Posts
    94
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to declare a variable as polymorphic?

    the problem is solved because all classes I wanted to use are subclassed from their base class, so that I can just declare a variable as a pointer to the base class...

    best regards,

    Vitali

Similar Threads

  1. how to declare a global variable right
    By Cruz in forum Newbie
    Replies: 13
    Last Post: 16th February 2010, 16:25
  2. Eclipse debugging: Unable to create variable object
    By PUK_999 in forum Installation and Deployment
    Replies: 0
    Last Post: 20th August 2009, 21:42
  3. nmake error during .pro compiling
    By mattia in forum Installation and Deployment
    Replies: 5
    Last Post: 18th June 2008, 10:15
  4. how to declare a friend variable ?
    By probine in forum General Programming
    Replies: 5
    Last Post: 27th March 2006, 15:00
  5. custom plugin designer property with out a variable?
    By high_flyer in forum Qt Programming
    Replies: 1
    Last Post: 15th March 2006, 19:11

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.