Book a Demo

Author Topic: How to declare an operator in a class (classmodel)  (Read 2164 times)

viettrung

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
How to declare an operator in a class (classmodel)
« on: December 25, 2006, 07:01:28 am »
Hi all,

I am a newbie in EA. I have built a class CDateTime in class model, in which I try to define a binary operator + (on date time). To do so, I've added an operation named + with stereotype : operator to CDateTime class. However, after generating C++ code, I have not got the correct syntax code, specifically the keyword operator does not appear in front of +.

Any suggestions are welcome! Thank you!
« Last Edit: December 25, 2006, 09:16:25 am by viettrung »

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: How to declare an operator in a class (classmo
« Reply #1 on: December 25, 2006, 04:46:56 pm »
1) Search for answers in the Forum (Try:
operator C++
  or
operator CPP
- set days to at least 600)

2) that doesn't supply enough answers, create a small code fragment with the correct C++ syntax,
Reverse Engineer it into EA and then Forward Engineer it out.  If the output code is OK, then the EA model representation is there for you to copy.

If it doesn't work properly, formally report the bug to Sparx using the Support Link at top of the page,, attaching your code snippet.

HTH,
Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

viettrung

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: How to declare an operator in a class (classmo
« Reply #2 on: December 26, 2006, 02:43:42 am »
Hi Paolo F Cantoni,

I could not find out the anwser in the forum. So I have tried with your second suggestion, means: correcting the code (.h,.cpp) and then synchronizing the class with code. That works simply very well!:)  Thank you so much, Paolo F Cantoni!

Here is the solution (how to declare an operator in a class in class model) for one who may need:

- Create a new operation in the class.

- In the field of Name: put keyword "operator" right before the operator symbol (e.g. in my case: Name: operator +)

Regards,

.Viet Trung.
« Last Edit: December 26, 2006, 02:51:15 am by viettrung »