My compiler do not support this style of coding

Started by
6 comments, last by savagerx 22 years, 5 months ago
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
The road may be long, wind may be rough. But with a will at heart, all shall begone. ~savage chant
Advertisement
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!]
BTW: I didn''t look at your code much, so take my advice as if it were under the assumption that your real code has no errors.

[Resist Windows XP''s Invasive Production Activation Technology!]
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
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 &ltclass T>class myclass{// class declaration};//// instantiate myclass for int:class myclass&ltint>; 
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.
Dactylos,
You''re right. My bad. The syntax is supported under MSVC5+, but I don''t know about BCB5...
I was talking about Borland C++ 5.0, the old one. I haven''t used the new one.

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

This topic is closed to new replies.

Advertisement