Results 1 to 4 of 4

Thread: struct problem...

  1. #1
    Join Date
    Feb 2007
    Posts
    47
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question struct problem...

    I just want to try to use struct for my further usage.
    In the header file I define a struct:
    struct refer{
    double Are;
    double Ere;
    };

    class newstruct{
    public:
    newstruct();
    struct refer refer1;
    struct refer1 a(double b,double c);
    };
    In the .cpp file:
    struct refer1 newstruct::a(double b,double c){
    refer1.Are=b;

    refer1.Ere=c;
    cout<<refer1.Aref<<endl
    <<refer1.Eref<<endl;

    return(refer1);
    }
    the error:
    NewStruct.cpp: In member function `refer1 newstruct::a(double, double)':
    NewStruct.cpp:7: error: return type `struct refer1' is incomplete
    NewStruct.cpp:12: error: conversion from `refer' to non-scalar type `refer1' requested
    Can anyone tell me the problem?Thank you very much!
    Best Regards!
    Last edited by hiuao; 5th April 2007 at 06:08.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: struct problem...

    U should have posteed this in General programming... nothing specific to Qt...

    neways this should help u...


    Qt Code:
    1. struct refer{
    2. double Are;
    3. double Ere;
    4. };
    5.  
    6. class newstruct{
    7. public:
    8. newstruct();
    9. struct refer refer1;
    10. struct refer a(double b,double c);
    11. };
    12. In the .cpp file:
    13. refer newstruct::a(double b,double c)
    14. {
    15. refer1.Are=b;
    16.  
    17. refer1.Ere=c;
    18. cout<<refer1.Aref<<endl
    19. <<refer1.Eref<<endl;
    20.  
    21. return(refer1);
    22. }
    23.  
    24. newstruct objNewstruct;
    25. refer r2 = objNewstruct.a(3,4);
    To copy to clipboard, switch view to plain text mode 


    hope this helps...

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

    hiuao (5th April 2007)

  4. #3
    Join Date
    Feb 2007
    Posts
    47
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Red face Re: struct problem...

    Quote Originally Posted by aamer4yu View Post
    U should have posteed this in General programming... nothing specific to Qt...

    neways this should help u...


    Qt Code:
    1. struct refer{
    2. double Are;
    3. double Ere;
    4. };
    5.  
    6. class newstruct{
    7. public:
    8. newstruct();
    9. struct refer refer1;
    10. struct refer a(double b,double c);
    11. };
    12. In the .cpp file:
    13. refer newstruct::a(double b,double c)
    14. {
    15. refer1.Are=b;
    16.  
    17. refer1.Ere=c;
    18. cout<<refer1.Aref<<endl
    19. <<refer1.Eref<<endl;
    20.  
    21. return(refer1);
    22. }
    23.  
    24. newstruct objNewstruct;
    25. refer r2 = objNewstruct.a(3,4);
    To copy to clipboard, switch view to plain text mode 


    hope this helps...
    I just change the defination of struct a,just as you said.Then its ok!
    Thank you very much!

  5. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: struct problem...

    struct a ???
    i guess a is a member function of the class newstruct.
    The mistake u were making is that u were trying to return refer1... in return u mention return types,,,, not return data.

Similar Threads

  1. Replies: 16
    Last Post: 23rd May 2008, 10:12
  2. Problem porting Kivio MP on win32 from Qt 3 to Qt 4
    By Amanda in forum Qt Programming
    Replies: 2
    Last Post: 26th October 2006, 19:40
  3. problem with saving QCstrings
    By nass in forum Qt Programming
    Replies: 3
    Last Post: 5th October 2006, 15:12
  4. Replies: 16
    Last Post: 7th March 2006, 15:57
  5. Problem with pointers while using localtime() and time()
    By jamadagni in forum General Programming
    Replies: 7
    Last Post: 11th January 2006, 15:48

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.