• Advertisement
Sign in to follow this  

[Solved] Template question

This topic is 4047 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm not a beginner programmer, but I've ran into a simple template piece I just don't understand:
template<typename T> struct CImg {
    ...
   CImg(const char *const filename) { ... }
   ...
};

const char* file_i = "...";
const CImg<unsigned char> image = CImg<>(file_i);



What does "CImg<>" mean, and why in earth is it allowed? (It compiles on both VC++ 2005 and gcc.) [Edited by - Zbyl on January 28, 2007 6:22:22 AM]

Share this post


Link to post
Share on other sites
Advertisement
Judging by the name CImg, I guess that's supposed to be a class. It's probably allowed because the final line just a different way of calling the constructor, and you already specified the type on the left hand side. You shouldn't have to specify a template parameter twice... No doubt there's a more scientific explanation. I'd do this to avoid weirding people out:

const CImg<unsigned char> image(file_i);

Share this post


Link to post
Share on other sites
Surely the exact piece of code that you posted does not compile on any compiler, what with the ellipses and the missing class keyword.

Anyway, the following program does *not* compile on gcc 4:

template <typename T>
class foo
{
};

int main()
{
foo<int> f = foo<>();
}

Share this post


Link to post
Share on other sites
Sorry... The problem is solved.
There was this line above:
template<typename T=float> struct CImg;

I missed it, because the CImg library header is 21000 lines of code...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement