B
Basil
Hello.
Compiler BCB60.
There is a simple example:
class a1 {
int v;
public:
a1 ():v (0) {}
a1 (int v1):v (v1) {}
a1 (a1& a):v (a.v) {}
a1& operator = (a1& a) {v=a.v; return *this;}
};
a1 fun (a1 a) {
a1 ex=a;
return ex;
}
int main (int argc, char* argv [])
{
a1 ex1 (1);
a1 ex2 (2);
a1 ex3 (3);
ex2=ex1;
ex3=fun (ex1); /*is here diagnostics [C ++ Error] Unit1.cpp (24): E2285 Could not
find a match for 'a1:: operator = (a1)' */
return 0;
}
The argument of function "fun" pass by value. The result comes back by value too.
If class a1 have member: a1& operator = (const a1& a) {v=a.v; return *this;},
error do not occur. But return value of "fun" is not const. I want return
non-const value from "fun", but I may not make it.
Questions:
1. Why returned value is not cast to type of the reference?
2. How to overcome it?
Thank
Basil
Compiler BCB60.
There is a simple example:
class a1 {
int v;
public:
a1 ():v (0) {}
a1 (int v1):v (v1) {}
a1 (a1& a):v (a.v) {}
a1& operator = (a1& a) {v=a.v; return *this;}
};
a1 fun (a1 a) {
a1 ex=a;
return ex;
}
int main (int argc, char* argv [])
{
a1 ex1 (1);
a1 ex2 (2);
a1 ex3 (3);
ex2=ex1;
ex3=fun (ex1); /*is here diagnostics [C ++ Error] Unit1.cpp (24): E2285 Could not
find a match for 'a1:: operator = (a1)' */
return 0;
}
The argument of function "fun" pass by value. The result comes back by value too.
If class a1 have member: a1& operator = (const a1& a) {v=a.v; return *this;},
error do not occur. But return value of "fun" is not const. I want return
non-const value from "fun", but I may not make it.
Questions:
1. Why returned value is not cast to type of the reference?
2. How to overcome it?
Thank
Basil