Advertisement

overloading the insertion (<<) operator, problem when using it,

Started by June 28, 2002 08:51 AM
4 comments, last by mickey 22 years, 4 months ago
hiya,
  
<pre>
someclass& operator <<(char *string)
{
...
}

someclass *object = new someclass;
object << "hello"; // error

// now when i want to use that, it should be this way,

*object << "hello";
</pre>
  
but i wouldn''t like it to be that way, ie, *object << "..."; so is there any other way around this? thanks,
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
someclass object;
object << "hello";

?
---visit #directxdev on afternet <- not just for directx, despite the name
Advertisement
er, no, i would like to declare that object as a pointer,
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
I don''t really see the problem. You want to do an operation on something that is pointed to, so you have to use *.

Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions
If you overload a free-standing binary operator, then one of the arguments must be of user-defined type. If you code this:

  someclass *object = new someclass;object << "hello";  


Then both operands are of pointer type, so it is not possible to overload.
ah i see, so there''s no possible way, thanks!!
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,

This topic is closed to new replies.

Advertisement