Tuesday, July 28, 2009

C++ programming error - friend function?

i have an error on this line of code:


friend void operator then(TMembershipDegree Op1, TSolutionVariable %26amp;Op2);





the error says friend must be functions or classes. but ive already


define then in a header class.





can anyone help

C++ programming error - friend function?
There is no operator 'then' in the C++ language. You can't make new operators, you can only overload (most of) the operators that already exist.





Regardless, when overloading an operator, there would be no space between the keyword 'operator' and the symbol. For instance:





myClass myClass::operator+(const myClass%26amp;);





EDIT: Helps me to answer... but it certainly doesn't help your credibility.





As I stated, the operator keyword should contain no space between the symbol. Which would mean to say you'd need to put 'operatorthen', which would, of course, not work because it wouldn't match your preprocessor directive. This logic is completely ignoring the fact that you can't make preprocessor definitions of operators, anyway, and '%26gt;%26gt;==' is not a C++ operator, either. Not to mention your #ifndef and #define directives don't match so your header guard is useless. Long story short, you can't do what you're trying to do, so stop it.





EDIT 2:


Oh, and I didn't mean stop programming... I think you should keep practicing and get better. I mean stop trying to overload operators and using preprocessor directive until you study them.


No comments:

Post a Comment