c++::overloading made-up operators?
i have a question (which really doesn''t matter since i''m not using it for anything, but i am curious anyways as it could be usefule some day):
obviously you can overload operators in c++... but can you create your own?
for example, i could overload the operator + for a class i built, but can i create a new operator @@ for it? or am i restricted to using already-defined operators (even if they have nothing to do with the original operation)?
--- krez (krezisback@aol.com)
Only existing ones, and not all of them. The ternary operator ?:, the dot operator and one or two others cannot be overloaded.
Fantastic doctrines (like Christianity or Islam or Marxism or Microsoft-bashing) require unanimity of belief. One dissenter casts doubt on the creed of millions. Thus the fear and hate; thus the torture chamber, the iron stake, the gallows, the labor camp, the psychiatric ward - Edward Abbey
Fantastic doctrines (like Christianity or Islam or Marxism or Microsoft-bashing) require unanimity of belief. One dissenter casts doubt on the creed of millions. Thus the fear and hate; thus the torture chamber, the iron stake, the gallows, the labor camp, the psychiatric ward - Edward Abbey
"Microsoft bashing" doctrine, huh :-)
No, it''s just a true feeling, called "hate".
Some people tend to hate others that appear unfair/wicked/"evil"
/lotsa other negative words
to them, especially those who try to be a "good human" themselves, and don''t like to be assholes.
/me points to the above poster as someone who has clearly missed the point entirely.
Fantastic doctrines (like Christianity or Islam or Marxism or Microsoft-bashing) require unanimity of belief. One dissenter casts doubt on the creed of millions. Thus the fear and hate; thus the torture chamber, the iron stake, the gallows, the labor camp, the psychiatric ward - Edward Abbey
Fantastic doctrines (like Christianity or Islam or Marxism or Microsoft-bashing) require unanimity of belief. One dissenter casts doubt on the creed of millions. Thus the fear and hate; thus the torture chamber, the iron stake, the gallows, the labor camp, the psychiatric ward - Edward Abbey
you could overload normal operators, and then use a define statement to mask them.
#define attacks +
void main()
{
class1 attacks class2;
}
however, defines must start with an alpha character and only contain alphanumeric chars.
though, im not sure if this whole idea will result in good or bad things.
and Fines is right, you can only overload already recognized operators, and most of them too. the symbols follow normal precedence order.
these are the symbols you cant overload: . .* :: ?:
you also cannot over load general symbols that may not be operators, like #
#define attacks +
void main()
{
class1 attacks class2;
}
however, defines must start with an alpha character and only contain alphanumeric chars.
though, im not sure if this whole idea will result in good or bad things.
and Fines is right, you can only overload already recognized operators, and most of them too. the symbols follow normal precedence order.
these are the symbols you cant overload: . .* :: ?:
you also cannot over load general symbols that may not be operators, like #
Arild Fines:
yeah, you''re right, sorry. Just looked through these pages
in a hurry, saw your signature, just posted, went to other page...
Didn''t care about topic.
Again, sorry.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement