One way might be to use an inner constructor:On Saturday, September 21, 2013 01:29:29 PM Tim Keitt wrote:
> I want to create a lot of instances of a composite type, but give each a
> globally unique id. In C++ I would use a static member for access within
> constructors. Any thoughts on how to accomplish that?
module MyModule
type MyObject
data::ASCIIString
id::Int
ID::Int = 0
function MyObject(str::ASCIIString)
ID += 1
new(str, ID)
end
end
end
julia> o1 = MyModule.MyObject("Hi")
MyObject("Hi",1)
julia> o2 = MyModule.MyObject("there")
MyObject("there",2)