If we pass a 'reference type' by 'ref' and thus a new object will be allocated in func1(), wouldn't the cat1class no longer be pointing to the CatClass allocated in main()? Thereby causing a memory leak.
Correct, public to the module. I suspect (though I'd have to verify) this might have been in effort to avoid things like friend functions / friend classes which could otherwise just be defined in the same module.
I am happy that you do videos on OOP in D.
Cheers!
If we pass a 'reference type' by 'ref' and thus a new object will be allocated in func1(), wouldn't the cat1class no longer be pointing to the CatClass allocated in main()? Thereby causing a memory leak.
D has a garbage collector -- thus it will reclaim that object if there are no longer references pointing to it 🙂
Finally!
Many more lessons to come on D and classes 🙂
@@MikeShah Excellent!!!
TBH: I was not aware that members (fields) of classes are public by default in D (?)
Correct, public to the module. I suspect (though I'd have to verify) this might have been in effort to avoid things like friend functions / friend classes which could otherwise just be defined in the same module.
Ah, and I found the note here on avoiding friend classes by having things in the same module: dlang.org/articles/cpptod.html