Links

Categories

Tags


« | Main | »

Automatic type conversion

By Jewe | October 29, 2012

class Bar;

// define a new type
class Foo
{
    method Foo() { }
    method Foo(Bar b) { }
    method Bar convertor() { return new Bar(); }
}

// define another new type
class Bar
{
    method Bar() { }
}

function string main(const string[] args)
{
    Foo foo = new Foo(); // make a Foo
    Bar bar = new Bar(); // make a Bar

    foo = bar;           // this will actually construct a new Foo from 'bar'
                         // it's the same as: foo = new Foo(bar);

    bar = foo;           // this will actually call Foo::convertor()

    return "";
}

Topics: code examples | Comments Off on Automatic type conversion

Comments are closed.