Thread overview | ||||||
---|---|---|---|---|---|---|
|
January 08, 2017 template instance does not match template declaration | ||||
---|---|---|---|---|
| ||||
Hi, On my first attempt to create a templated class, I'm hitting an issue that I can't seem to resolve. I've dustmite'd the code down to: class Cache(O, K, F) { } void main() { class BasicObject { } BasicObject lookupBasicObject() { } Cache!(BasicObject, string, lookupBasicObject); } and I'm hitting the following error: cache.d(23): Error: template instance Cache!(BasicObject, string, lookupBasicObject) does not match template declaration Cache(O, K, F) Any help would be much appreciated in understanding what I am doing wrong. Thanks. Take care, Fabrice. |
January 08, 2017 Re: template instance does not match template declaration | ||||
---|---|---|---|---|
| ||||
Posted in reply to Fabrice Marie | On Sunday, 8 January 2017 at 03:27:26 UTC, Fabrice Marie wrote:
> Hi,
>
> On my first attempt to create a templated class, I'm hitting an issue that I can't seem to resolve.
>
> I've dustmite'd the code down to:
>
> class Cache(O, K, F)
> {
> }
>
>
> void main()
> {
> class BasicObject
> {
> }
>
> BasicObject lookupBasicObject() {
> }
>
> Cache!(BasicObject, string, lookupBasicObject);
> }
>
>
> and I'm hitting the following error:
>
> cache.d(23): Error: template instance Cache!(BasicObject, string, lookupBasicObject) does not match template declaration Cache(O, K, F)
>
> Any help would be much appreciated in understanding what I am doing wrong.
>
> Thanks.
>
> Take care,
> Fabrice.
By default template parameters are Types. lookupBasicObject is not.
change this `class Cache(O, K, F)` to `class Cache(O, K, alias F)`
and it should work.
|
January 08, 2017 Re: template instance does not match template declaration | ||||
---|---|---|---|---|
| ||||
Posted in reply to Fabrice Marie | On Sunday, 8 January 2017 at 03:27:26 UTC, Fabrice Marie wrote:
> void main()
> {
> ....
> Cache!(BasicObject, string, lookupBasicObject);
> }
In addition to what Nicholas Wilson said, what you're doing here is the equivalent of writing `int;`. It doesn't make any sense as Cache!(...) is a type, and you are declaring a variable of that type... except you're not providing a variable name so the syntax is wrong. After you've fixed the other problem change it to this:
Cache!(BasicObject, string, lookupBasicObject) c;
|
January 15, 2017 Re: template instance does not match template declaration | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta | On Sunday, 8 January 2017 at 05:45:52 UTC, Meta wrote:
> On Sunday, 8 January 2017 at 03:27:26 UTC, Fabrice Marie wrote:
>
>> void main()
>> {
>> ....
>> Cache!(BasicObject, string, lookupBasicObject);
>> }
>
> In addition to what Nicholas Wilson said, what you're doing here is the equivalent of writing `int;`. It doesn't make any sense as Cache!(...) is a type, and you are declaring a variable of that type... except you're not providing a variable name so the syntax is wrong. After you've fixed the other problem change it to this:
>
> Cache!(BasicObject, string, lookupBasicObject) c;
Thanks a lot! exactly what I needed.
|
Copyright © 1999-2021 by the D Language Foundation