Results 1 to 6 of 6

Thread: Returned value of a function called from another class

  1. #1
    Join Date
    Jan 2012
    Posts
    83
    Qt products
    Qt4
    Platforms
    Windows

    Default Returned value of a function called from another class

    Hello!
    I am facing a difficult problem now. I would be grateful if you could help me.
    I have created a function in a class and I want to use the same function in another class. The problem is that when I am calling this function, I have a message error like this: " no match for 'operator=' in 'variable3 = ...'"
    In my code, I have created an instance of the class A. From the class B (in a function (g)), I am calling the function (f) of the class A. I want to use variable3 for further purposes.
    Could you tell me please where the matter is?

    Many thanks in advance.

    Here is my code:
    class header files.

    Qt Code:
    1. class A
    2. {public:
    3.  
    4. double f(double);
    5. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "A.h"
    2. class B
    3. {public:
    4. double g(A &file, double);
    5. }
    To copy to clipboard, switch view to plain text mode 

    class cpp files
    Qt Code:
    1. #include "A.h"
    2. double A::f(double variable1)
    3. {
    4. // do stuff on variable1
    5. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "A.h"
    2. #include "B.h"
    3. double B::g(A &file, double variable2)
    4. {
    5. double variable3;
    6. variable3 = file.f(variable2);
    7. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Returned value of a function called from another class

    I am sure the code you posted will not give the error you said, it will give some other error.

    Anyway here are your things to check for
    1. Make sure you have include guards in the header files.
    2. Make sure the class definition of class is terminated with ";"
    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 2012
    Posts
    83
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Returned value of a function called from another class

    Hello Reddy and many thanks for your reply.
    The two points you mentioned are correct in my code. The error mesmessage ist like that.
    I am wondering why the error message appears.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Returned value of a function called from another class

    As Santosh said, there is nothing in the code you posted that would generate that error. So we can only conclude that the code you posted is not the actual code causing the error.

    If in fact "variable3" is not a double but is of type "class C", then this error could occur if you have not defined operator=() for class C that takes an argument of whatever A::f() returns.

  5. #5
    Join Date
    Jan 2012
    Posts
    83
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Returned value of a function called from another class

    OK. Th ecode posted was simplified. I will check again.
    Thanks for your help!

  6. #6
    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: Returned value of a function called from another class

    How is that related to "Qt Programming"?
    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. Replies: 11
    Last Post: 5th September 2012, 20:47
  2. Replies: 5
    Last Post: 23rd September 2011, 09:44
  3. Replies: 3
    Last Post: 17th September 2011, 13:04
  4. error message appears when function is called
    By babygal in forum Qt Programming
    Replies: 11
    Last Post: 14th June 2010, 23:49
  5. Replies: 3
    Last Post: 16th May 2007, 11:07

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.