Results 1 to 3 of 3

Thread: Inheritance of nested class

  1. #1
    Join Date
    Mar 2011
    Posts
    120
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Inheritance of nested class

    hi everyone,

    I have 2 nested class (nest_1,nest_2).1st class is inherited by 2nd class and i want to access member of 1st nested class in a function of 2nd class.
    I tried like...

    .h file
    Qt Code:
    1. class MainWindow : public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. explicit MainWindow(QWidget *parent = 0);
    7. ~MainWindow();
    8. int main_data;
    9.  
    10.  
    11. private:
    12. Ui::MainWindow *ui;
    13. public:
    14. class nest_1
    15. {
    16. public:
    17. int data1;
    18. };
    19. class nest_2 : public nest_1
    20. {
    21. public:
    22. int data2;
    23. int test();
    24. };
    25. };
    26.  
    27. class A : public MainWindow
    28. {
    29. public:
    30. int data;
    31.  
    32. int test();
    33. };
    To copy to clipboard, switch view to plain text mode 


    .cpp file

    Qt Code:
    1. int MainWindow::nest_2::test()
    2. {
    3. // here i want to access data1
    4. }
    5.  
    6.  
    7. int A::test()
    8. {
    9. main_data = 0; //here i am able to access main_data
    10. }
    To copy to clipboard, switch view to plain text mode 


    I tried same thing for MainWindow and A.It is working.But for nested class it is not.

    Can any one tell me how to access it or any error in my code ?

    with regards
    bibhu.

  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: Inheritance of nested class

    Works for me...

    Cpp Code:
    1. class Outer {
    2. public:
    3.  
    4. void call() { b.method(); }
    5. private:
    6. class A {
    7. public:
    8. int x;
    9. };
    10.  
    11. class B : public A {
    12. public:
    13. void method() { x = 7; }
    14. };
    15.  
    16. B b;
    17. };
    18.  
    19.  
    20. int main() {
    21. Outer o;
    22. o.call();
    23. return 0;
    24. }
    To copy to clipboard, switch view to plain text mode 
    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.


  3. #3
    Join Date
    Mar 2011
    Posts
    120
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Inheritance of nested class

    thanks for reply........
    i will try it.

    if you want to use scope resolution operator(: then how you will use it.

Similar Threads

  1. Inheritance confusion - which class made inheritating from QObject
    By kornicameister in forum Qt Programming
    Replies: 1
    Last Post: 23rd December 2010, 09:54
  2. destroing nested layout
    By mastupristi in forum Qt Programming
    Replies: 2
    Last Post: 30th November 2009, 08:58
  3. Nested Layout
    By starcontrol in forum Qt Programming
    Replies: 2
    Last Post: 9th April 2008, 12:47
  4. nested tables
    By Jeroen van der Waal in forum Qt Programming
    Replies: 1
    Last Post: 6th June 2007, 17:12
  5. Nested Plugins
    By Luis Rodriguez in forum Qt Programming
    Replies: 1
    Last Post: 10th March 2006, 22:00

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.