Initializers from generic types won't be inherited in swift?
<p>Here is my code:</p><pre><br /><code>public class A<T:Any> { <br /> public init(n:Int) { <br /> print("A")<br /> } <br />} <br />public class B:A<Int>{}<br />public class C:B{}<br />let x = C(n:123)<br /></code><br /></pre><p>And this fails compilation and yells such error:</p><pre><br /><code>repl.swift:9:9: error: 'C' cannot be constructed because it has no accessible initializers<br /></code><br /></pre><p>And the following code can be compiled.</p><pre><br /><code>public class A { <br /> public init(n:Int) { <br /> print("A")<br /> } <br /> } <br /> public class B:A{}<br /> public class C:B{}<br /> let x = C(n:123)<br /></code><br /></pre><p>Shouldn't requirement types specified generic types' initializers be inherited?</p><br /><h2>Click here view more answers <a href="%20http://stackoverflow.com/questions/34525368/initializers-from-generic-types-wont-be-inherited-in-swift">http://ift.tt/1mhPC6v</a></h2>
Nhận xét
Đăng nhận xét