G
Grizlyk
1. Can abybody explain me why C++ function can not be overloaded by its
return type? Return type can has priority higher than casting rules.
For example:
char input(); //can be compiled to name "input$char$void"
int input(); //can be compiled to name "input$int$void"
....
int i= 3+'0'+input(); //can be compiled to:
int(3)+int('0')+input$int$void()
char ch= 3+'0'+input(); //can be compiled to:
char(3)+char('0')+input$char$void()
Are any understandable obstacles exist? There is some profit for such
overloading, for example, we would may not write:
char input_char();
int input_int();
2. Cast is only by return type. Am i right? For example:
A a;
struct B{ static B& operator+ (const A&, const B&); };
B b;
struct B{ static C& operator+ (const B&, const C&); };
C c;
struct D{
static D& operator+ (const D&, const D&);
D(const C&);
};
D d=a+b+c; //give me
d.operator=( D:perator+( D:perator+( D(a)+D(b) ), D(c) ) );
or declared "class_name:perator+" change cast
d.operator=( D( C:perator+ ( B:perator+(a,b), c ) ) );
Or is it FAQ question?
return type? Return type can has priority higher than casting rules.
For example:
char input(); //can be compiled to name "input$char$void"
int input(); //can be compiled to name "input$int$void"
....
int i= 3+'0'+input(); //can be compiled to:
int(3)+int('0')+input$int$void()
char ch= 3+'0'+input(); //can be compiled to:
char(3)+char('0')+input$char$void()
Are any understandable obstacles exist? There is some profit for such
overloading, for example, we would may not write:
char input_char();
int input_int();
2. Cast is only by return type. Am i right? For example:
A a;
struct B{ static B& operator+ (const A&, const B&); };
B b;
struct B{ static C& operator+ (const B&, const C&); };
C c;
struct D{
static D& operator+ (const D&, const D&);
D(const C&);
};
D d=a+b+c; //give me
d.operator=( D:perator+( D:perator+( D(a)+D(b) ), D(c) ) );
or declared "class_name:perator+" change cast
d.operator=( D( C:perator+ ( B:perator+(a,b), c ) ) );
Or is it FAQ question?