Archived

This topic is now archived and is closed to further replies.

My compiler do not support this style of coding

This topic is 5895 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 using Borland C++ 5.02 as instructed by my school. Recently, I'm trying to "Specialize" my template as follows: Original template:
    
template <class Type1>class myclass{
//my code goes here

};
  

Attempting to specialize using this style:
      
template<> class myclass<int>{
//my code goes here

};
    
And the result is ERROR: invalid template parameters. But the school actually demands that we must use Borland C++. What can I do? or is there an alternative way to specialize it? or are there any newer versions of Borland C++? The road may be long, wind may be rough. But with a will at heart, all shall begone. ~savage chant Edited by - savagerx on October 23, 2001 3:50:45 PM Edited by - savagerx on October 23, 2001 3:52:50 PM Edited by - savagerx on October 23, 2001 3:53:47 PM

Share this post


Link to post
Share on other sites
The older versions of Borland isn''t fully up to date with the C++ standards (I know, I own BC++ 5.0 ). The newer Borland compilers should work fine. You can download the newer borland 5.5 from their site (for free) or try GCC (GCC for DOS is DJGPP, GCC for Windows in MinGW which is often used through DevC++).

[Resist Windows XP''s Invasive Production Activation Technology!]

Share this post


Link to post
Share on other sites
template<> should have int in the <> if you want to use class myclass with only an int.

However, I recommend using the first example

    
template <class Type1>
class myclass
{
//my code goes here

};


because it allows you to use any type.

Invader X
Invader's Realm

Edited by - Invader X on October 23, 2001 8:55:30 PM

Share this post


Link to post
Share on other sites
Specialization, or explicit instantiation (useful if you want to export a library of template classes/functions with support for only a given number of types), is implemented as follows:

template <class T>
class myclass
{
// class declaration
};
//
// instantiate myclass for int:
class myclass<int>;

Share this post


Link to post
Share on other sites
Oluseyi,
That''s not a specialization. A specialization is when you want to have a template class, but for certain types the implementation should be different than the generic one.

Consider for example a vector class that uses an array internally for storage. A specialisation for the bool type could instead use a bitfield to store each boolean value as one bit.

Share this post


Link to post
Share on other sites