OOPortal OOPortal


User Defined Types  «Prev 

Anonymous Objects


For anonymous objects, the name is omitted, but the colon is retained, like this:
:Point
x=50.0
y=32.0

Anonymous objects are commonly used in diagrams that show one object contained in another object. The name of the object is taken from the containing class. They can also be used to show samples of an object that may not be used in any particular part of the code.
An anonymous object is basically an object which the compiler creates a class for. Anonymous objects are objects without a name.
Example:
class Foo {
};

void bar(Foo const &foo) {
}

int main() {
    Foo(); // creates an anonymous Foo and immediately destroys it
    bar(Foo()); // creates an anonymous Foo which lives until bar returns
}