PDA

View Full Version : Returned value of a function called from another class



Stanfillirenfro
1st February 2013, 18:58
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.


class A
{public:

double f(double);
}


#include "A.h"
class B
{public:
double g(A &file, double);
}

class cpp files

#include "A.h"
double A::f(double variable1)
{
// do stuff on variable1
}


#include "A.h"
#include "B.h"
double B::g(A &file, double variable2)
{
double variable3;
variable3 = file.f(variable2);
}

Santosh Reddy
1st February 2013, 19:20
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 ";"

Stanfillirenfro
1st February 2013, 19:29
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.

d_stranz
1st February 2013, 20:11
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.

Stanfillirenfro
1st February 2013, 20:21
OK. Th ecode posted was simplified. I will check again.
Thanks for your help!

wysota
6th February 2013, 13:02
How is that related to "Qt Programming"?