template question

akcom CppCoder at gmail.com
Wed May 31 16:55:40 PDT 2006


I am translating a C macro I use while manipulating PE files, it has the 
following definition:

#define incptr( Ptr, Increment, CastType ) (CastType *)( (unsigned 
long)(Ptr) + (unsigned long)(Increment) )

I thought using templates would be best, so I came up with the following:

template IncPtr( Ptr:Ptr *, int Increment, T )
{
	const IncPtr = cast(T *)( cast(uint)Ptr + Increment );
}

unfortunately, when I try to use it with something like the following...
IMAGE_DOS_HEADER *dosHeader;
IMAGE_NT_HEADERS *ntHeaders;

ntHeaders = IncPtr!( dosHeader, dosHeader.e_lfanew, IMAGE_NT_HEADERS );

I get the following compilation errors:
pefile.d(194): template instance IncPtr!(dosHeader,incr,ImageNtHeaders ) 
does not match any template declaration
pefile.d(194): voids have no value
pefile.d(194): cannot implicitly convert expression 
(IncPtr!(dosHeader,incr,Imag
eNtHeaders )) of type void to ImageNtHeaders *

any ideas?



More information about the Digitalmars-d-learn mailing list