Mail Archives: djgpp/1997/08/13/11:06:31
In article <5sp4ql$2m1 AT freenet-news DOT carleton DOT ca>, ao950 AT FreeNet DOT Carleton DOT CA (Paul Derbyshire) writes:
> What exactly is the list of operators you can overload? As in, what
> combinations of nonalphabetic symbols can be used as operators? It'd be
> nice to have a full list. My C++ documentations don't specify, they say
> how to overload operators, and so forth, but don't list the symbols or
> symbol pairs that can be used legitimately as operators, as in, what is
> allowed in place of ?? in:
>
> friend vector &operator?? (vector &a, vector &b);
>
> and so forth.
> --
> .*. Where feelings are concerned, answers are rarely simple [GeneDeWeese]
> -() < When I go to the theater, I always go straight to the "bag and mix"
> `*' bulk candy section...because variety is the spice of life... [me]
> Paul Derbyshire ao950 AT freenet DOT carleton DOT ca, http://chat.carleton.ca/~pderbysh
You can overide all the standard C/C++ operators (including cast operators)
except . (member selection)
:: (static member selection)
?: (selection)
(I think this is the list, don't flame me if its wrong)
You can not create new operators, nor change the priority of existing operators
for the autoincrement/decrement operator, postfix form ie i++ and i--
the operator take a dummy integer as the second parameter to differentaite from
the prefix form.
ie
class foo
{
public:
operator++(); // pre-fix;
operator++(int); // post-fix
};
BTW operators can be written as member functions, if the left hand parameter
is the class varible ie.
class foo
{
public:
operator +(int);
}
and
class foo
{
friend operator +(foo,int);
}
and
class foo
{
operator +(foo,int);
}
extern operator +(foo,int);
are all the same, (for the caller) except the last one
cannot access non-public members of 'foo'
to define the code, for this first one use
foo::operator+(int i) { /* ......... */};
and for the second and third
operator+(foo f,int i) { /* ........ */ };
For casting, use something along these lines
class foo
{
public:
operator int();
}
this allows code like this
void goo(void)
{
foo f;
int i;
i=f;
}
Colin S. Miller
i96csm AT river DOT tay DOT ac DOT uk
- Raw text -