Thread overview
Question on class templates
Jun 07, 2013
Eric
Jun 07, 2013
anonymous
Jun 07, 2013
Eric
June 07, 2013
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
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
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.