I've got a doubt with cardinality. I can write code watching UML but I don't know how to respect cardinality.
How can I write properly a code respecting proposed cardinality?
In this case I have to write a code, using composition and cardinality 0,1 like in the picture: http://imagizer.imageshack.us/v2/800x600q90/809/5pm6.jpg
I write down my code, do you think it's right? Please, let me know how can I get better with cardinality in the code for exemple 0 or * or 1,1 or 0,* . Thank you everybody!
maybe, should it be void association(G g){gp=g;} ?
It would still be a dangling pointer. When you pass a value into this function, it will copy it. You then set the pointer to the address of this copied value. This value is then destroyed after the function call is finished, and the pointer becomes a dangling pointer.
Pass a reference to a G type in order to solve that problem.
While it may not be directly related to your problem, it's still important to code it correctly.