X
xuatla
Hi,
I have a class myClass, and want to define operator () with it. But I
don't want to change the class itself (e.g., sometime the class is
defined by other people and I cannot change it), but want to define it
outside the class. Is it possible to do so?
e.g.,
class myClass
{
//.....
data_type operator [] (size_t i){
//...
} ;
} ;
data_type operator () (const myClass& c, size_t i)
{
return c;
}
When I compiled this, I got an error:
error: `data_type operator()(const myClass&, size_t)' must be a
nonstatic member function.
Google gives:
An overloaded `operator ()' must be a non-static member function.
Does it mean that operator () cannot be overloaded out of class?
Thanks.
-X
I have a class myClass, and want to define operator () with it. But I
don't want to change the class itself (e.g., sometime the class is
defined by other people and I cannot change it), but want to define it
outside the class. Is it possible to do so?
e.g.,
class myClass
{
//.....
data_type operator [] (size_t i){
//...
} ;
} ;
data_type operator () (const myClass& c, size_t i)
{
return c;
}
When I compiled this, I got an error:
error: `data_type operator()(const myClass&, size_t)' must be a
nonstatic member function.
Google gives:
An overloaded `operator ()' must be a non-static member function.
Does it mean that operator () cannot be overloaded out of class?
Thanks.
-X