[Uml-devel] An issue with void operations in c++
Paulo Sehn
paulo.sehn at gmail.com
Thu Jul 14 20:29:58 UTC 2005
Hi folks,
I've been investigating an issue I found out performing the follow test:
open umbrello with an empty project
set the default language to c++
create a class
add an operation like void op1
run the code generator wizard and check the .h and .cpp, you'll get
something like this:
...(.h)
void op1 ();
...(.cpp)
void op1 () {
}
...
Ok, it's right, go ahead
Save the file and close umbrello.
Open umbrello and open the file you've saved.
run the code generator wizard and check the .h and .cpp, you got
something like this:
...(.h)
op1 ();
...(.cpp)
...
op1 () {
}
...
It's not ok because c++ forbids operation declaration without a return
type :), unless you are creating a constructor or a destructor.
So, lets check the xmi file, and it's looking like this :
...
<UML:Operation isSpecification="false" isLeaf="false"
visibility="public" xmi.id="63" isRoot="false" isAbstract="false"
name="op1" />
...
What's happend with our void operation ? As I can see I got an
operation without a return type and not a void operation like I was
expecting.
So, it's happening because this :
operation.cpp:242
void UMLOperation::saveToXMI( QDomDocument & qDoc, QDomElement & qElement ) {
...
if (m_pSecondary) {
if (m_pSecondary->getName() != "void") {
...
}
} else {
...
}
this line if (m_pSecondary->getName() != "void") is explicity
converting the void operation in an operation without return type. If
I comment this line, I get the behavior I'm expecting to c++ code
generation and I can create operations whitout returning type (i.e.
c++ constructors).
So, I would like to suggest the removal of the if I've describe above,
and I would like to know other comments about this issue.
Regards,
Paulo Sehn
More information about the umbrello-devel
mailing list