Hi,
how can I write new operator
for example:
bool operator G (int i,j){return i>j};
thankx
5 replies to this topic
#1
Posted 29 June 2010 - 02:34 AM
|
|
|
#2
Posted 29 June 2010 - 02:40 AM
you can't create new operators, you can only redifine existing ones, and then only with atleast one user-defined type as the parameters.
#3
Posted 29 June 2010 - 03:20 AM
Category
Operators, C++-Specific Keywords
Syntax
operator <operator symbol>( <parameters> )
{
<statements>;
}
<operator symbol> Don't be 'G' ?
This from help BCB 6.0
Operators, C++-Specific Keywords
Syntax
operator <operator symbol>( <parameters> )
{
<statements>;
}
<operator symbol> Don't be 'G' ?
This from help BCB 6.0
#4
Posted 29 June 2010 - 03:25 AM
again, you can't create new operators. You can only overload the ones you already have (and not all of them). If you could create new operators, then the compiler would need to have a very dynamic operator table, which C++ doesn't have (you define any operator you like in Prolog, and probably some other languages.)
See Operators in C and C++ - Wikipedia, the free encyclopedia
See Operators in C and C++ - Wikipedia, the free encyclopedia
#5
Posted 29 June 2010 - 09:17 PM
You can create class methods to do what you want. For example:
class A {
public:
size_t value;
bool G (const A& rhs) const {
return value > rhs.value;
}
};
Instead of doing something like this:
lhs G rhs;
You can do this:
lhs.G(rhs);
Edited by dargueta, 29 June 2010 - 09:18 PM.
Fixed syntax violation
sudo rm -rf /
#6
Posted 29 June 2010 - 11:34 PM
Thank I try it.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









