- D言語 Part34©2ch.net
277 :デフォルトの名無しさん[sage]:2015/11/21(土) 13:20:00.57 ID:1cOWOBSi - staticなメンバ関数からは、thisは見えないので
UFCS前提でいっそ外部に出して === import std.stdio; class Base {} class Hoge : Base {} class Other {} T[] takusanMake(T : Base)(lazy T d, int n) { auto ret = new T[n]; foreach (ref e; ret) { e = d(); } return ret; } void main() { auto hoge = (new Hoge).takusanMake(30); typeid(hoge).writeln; // Baseに暗黙変換できない型はNG //auto other = (new Other).takusanMake(30); } === こういうのはどうだろう (もっといい方法ありそう。。)
|
|