Thread overview |
---|
June 07, 2013 Question on class templates | ||||
---|---|---|---|---|
| ||||
interface Identity(V, K) { } class X(V, K) : Identity!(V, K) { private K k; public this(K k) { this.k = k; } } void main() { auto x = new X!(X, double)(6.0); } Hi - I have the code above, but the line in main() gives the following compile error: Error: template instance X!(X, double) does not match template declaration X(V, K) If I change the template parameter X to something else, like string, it compiles fine. But I want the Identity interface to know the type of the implementing class. Is that possible? Thanks, Eric |
June 07, 2013 Re: Question on class templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to Eric | On Friday, 7 June 2013 at 17:52:48 UTC, Eric wrote:
>
> interface Identity(V, K)
> {
> }
>
> class X(V, K) : Identity!(V, K)
> {
> private K k;
>
> public this(K k) { this.k = k; }
> }
>
> void main()
> {
> auto x = new X!(X, double)(6.0);
> }
>
> Hi -
>
> I have the code above, but the line in main() gives the following compile error:
> Error: template instance X!(X, double) does not match template declaration X(V, K)
>
> If I change the template parameter X to something else, like string, it compiles fine. But I want the Identity interface to know the type of the implementing class. Is that possible?
>
> Thanks,
>
> Eric
class X(K) : Identity!(X, K)
auto x = new X!(double)(6.0);
|
June 07, 2013 Re: Question on class templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to anonymous | On Friday, 7 June 2013 at 18:06:26 UTC, anonymous wrote:
> On Friday, 7 June 2013 at 17:52:48 UTC, Eric wrote:
>>
>> interface Identity(V, K)
>> {
>> }
>>
>> class X(V, K) : Identity!(V, K)
>> {
>> private K k;
>>
>> public this(K k) { this.k = k; }
>> }
>>
>> void main()
>> {
>> auto x = new X!(X, double)(6.0);
>> }
>>
>> Hi -
>>
>> I have the code above, but the line in main() gives the following compile error:
>> Error: template instance X!(X, double) does not match template declaration X(V, K)
>>
>> If I change the template parameter X to something else, like string, it compiles fine. But I want the Identity interface to know the type of the implementing class. Is that possible?
>>
>> Thanks,
>>
>> Eric
>
> class X(K) : Identity!(X, K)
>
> auto x = new X!(double)(6.0);
Oh... Duh... Thanks.
|
Copyright © 1999-2021 by the D Language Foundation