Book a Demo

Author Topic: C++ references (and code gen)  (Read 3508 times)

Andrew Cooke

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
C++ references (and code gen)
« on: June 04, 2005, 02:58:06 pm »
sorry for yet another newbie question, but how do i indicate that a parameter to a method is a c++ reference?  if i set the type to be Foo& (where "Foo" is a known class) then the autogenerated code does not include Foo.h (which is included if the type is plain Foo).

more generally, am i missing some good documentation somewhere on code generation?  i tried searchng these archives, but had no success, and i also looked at the ea documentation page.

thanks,
andrew

Andrew Cooke

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: C++ references (and code gen)
« Reply #1 on: June 04, 2005, 05:17:57 pm »
ah.  if i put the "&" at the start of the argument name, rather than at the end of the type, this works.

ok, so i guess that makes a strange kind of sense from c++'s binding rules (int * a, b is a pointer and an int, right?), but the "&" is type information, not part of a name.

so i'm still confused - is this really the right solution?  is it going to work for return types, for example?

thanks,
andrew

Andrew Cooke

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: C++ references (and code gen)
« Reply #2 on: June 04, 2005, 05:37:59 pm »
now i have the sameproblem with return types (pointers).  if i use namespaces and a pointer return time (with a "*" after the type) then the system doesn't recognise Foo* as existing and so doesn't append the correct namespace.

arrrrrgggghh!  how do i get this to work?  please??

Andrew Cooke

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: C++ references (and code gen)
« Reply #3 on: June 05, 2005, 08:03:09 am »
ok, it seems that i'm hitting the same problem reported at http://www.sparxsystems.com.au/cgi-bin/yabb/YaBB.pl?board=general;action=display;num=1117614705;start=4#4

the return values from methods are not specified with a namespace, whether thay have a "*" or not.  so either the namespace has to be specified, or the "using" statement has to be modified.

i'm surprised that what seems like basis functionality requires modification of the code generating system.  again, any confirmation that i'm on the right track would be appreciated.  i was expecting this to be less painful...

Andrew Cooke

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: C++ references (and code gen)
« Reply #4 on: June 05, 2005, 08:32:07 am »
more exactly, it seems that i need to surround everything in a namespace scope, since arguments and return values are not qualified.  maybe there's some setting i'm missing?

to recap:
- all my header files have "namespace Bar {...}"
- the source code for Foo, however, has, instead of "namespace ...", the declaration "using Bar::Foo", and arguments and return values have no explicit namespace.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: C++ references (and code gen)
« Reply #5 on: June 05, 2005, 04:45:09 pm »
As EA stands at the moment, you need to add the pointer or reference to the type.  Even though this means that EA doesn't recognise it as the same type as the class in the model because the type name no longer matches.  If you put it on the name instead, that solves one problem, but creates problems with code synchronisation.

Since that is true, EA then doesn't have the namespace information for the class when generating that parameter (or return type).  As a result you will also need to put the namespace qualification explicitly into the type.  Then you'll only have #include missing and that will need to be added manually.

Oh, and I get the namespace qualification on a return type (non-pointer) generated correctly.

Simon

Andrew Cooke

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: C++ references (and code gen)
« Reply #6 on: June 05, 2005, 04:56:42 pm »
hi,

thanks for responding, especially within the weekend.

but your reply was a bit depressing.  is this likely to improve?  i think ea is great - and thank you for producing such a wonderful thing at such a reasonable price - but this is a pretty serious hole, isn't it? (basic code generation in c++ doesn't work out of the box)

if it's not likely to be fixed soon, is that because code generation generally is quite a low priority, or because c++ itself has annoying details that don't mesh nicely with uml, or for some other reason?

or am i misunderstanding/confused/plain wrong?

thanks again,
andrew