I am new to templates and trying to implement Templates for creating ITK images:

template <class T,int D>
itk::Image< T, D>:: Pointer CreateITKImage(int *pnSize, double *pdSpacing = NULL)
{
typedef itk::Image< T, D> ImageType;
ImageType:: Pointer image = ImageType::New();
:
:
return image;
}

void main()
{
int Size[2] = {100,100};
itk::Image< int, 2>:: Pointer pImage;
pImage = CreateITKImage<int, 2>(Size);
}

Erors:

error C2146: syntax error : missing ';' before identifier 'CreateITKImage'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C3860: template argument list following class template name must list parameters in the order used in template parameter list

where as the the following code where i mention exclusively the type and dimension works fine.

template <class T,int D>
itk::Image< int, 2>:: Pointer CreateITKImage(int *pnSize, double *pdSpacing = NULL)
{
typedef itk::Image< T, D> ImageType;
ImageType:: Pointer image = ImageType::New();
:
:
return image;
}

itk::Image<T, D>::Pointer is a dependent type, meaning it depends on template parameters for the specific type definition. In these cases you need to specify that it's a type rather than an object:

template <class T,int D>
typename itk::Image<T, D>::Pointer CreateITKImage(int *pnSize, double *pdSpacing = NULL)
{
    // ...
}

Thanks Narue, It worked ! I understood the problem now. i appreciate your timely response.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.