Checking template parameter types of class

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon May 25 00:15:46 PDT 2015


On 05/24/2015 09:14 PM, tcak wrote:

 >>> Line 243: auto fileResourceList = new shared FileResourceList( 2
 >>> );
 >>>
 >>> main.d(243): Error: class main.FileResourceList(T) if (is(T :
 >>> FileResource)) is used as a type

struct and class templates do not have automatic type deduction; 
function templates do. The solution is to provide a convenience function 
template alongside the struct or class.

 > auto fileResourceList = new shared FileResourceList!FileResource( 2 );
 >
 > Then it works. The error message is not indicating directly this, though
 > logically it is still correct.

'if (is(T : FileResource))' part means "if T can implicitly be converted 
to FileResource". You still provide T so that it gets checked.

Ali



More information about the Digitalmars-d-learn mailing list