Solved

Template Specializaton in Builder 3

Posted on 1998-08-21
17
254 Views
Last Modified: 2010-04-10
I have a skeleton of a templat class A.  The class has a specialization for one of its member functions (operator () specialized for char) This works fine when I compile it in VC 5 (compiles and executes appropraitely).  However, when I compile it in Borland C++ Builder 3, I get the error that

[C++Error] borcon.cpp(12): Body has already been defined for function 'A<char>::operator ()(const char &) const'.

What is the correct syntax for the this specialization?  Is there a syntaz that will work on both?

template<class T> class A
{
public:
   int operator () (const T &t) const
   {
      return 0;
   }
};
//int A<char>::operator () (const T &t) const
template<> int A<char>::operator () (const T &t) const
{
   return 1;
}

int main(int argc, char **argv)
{
   A<char> ACh;
   int i = ACh('a');
   return 0;
}
0
Comment
Question by:nietod
  • 8
  • 8
17 Comments
 
LVL 8

Expert Comment

by:Answers2000
ID: 1170892
I think you syntax is correct and this is a compiler bug in Borland
0
 
LVL 22

Author Comment

by:nietod
ID: 1170893
That's what I'm afraid of.  But I was under the impression that Builder 3 conforms to the standard.  So I'm hoping to find some proof, or some indication that my syntax is incorrect and that the correct syntax works.  
0
 
LVL 3

Expert Comment

by:xyu
ID: 1170894
hi... try template without <> like that

template int A<char>::operator () (const T &t) const
 that was problem in previous versions of Borlands compiler...

or even create explicit redefinition of entire class :( It's very sad... bu Borland's compiler is not so compatible any more... I had some other examples of their bugs... that forced me to switch primarily to VC 5/6 :(


0
 
LVL 22

Author Comment

by:nietod
ID: 1170895
That gives me a new syntax error.  But I was getting tired of the old...

>> even create explicit redefinition of entire class
I thought of that and I could do that in this case, but haven't gotten around to it.  However, in general, that's not a realistic solutions, you may want to specialize one little member out of hundreds.  I'll see if I can fool with that today.

>>Borland's compiler is not so compatible any more... I had some
>> other examples of their bugs... that forced me to switch primarily
>> to VC 5/6
But Borland is so much faster.   I make a change to my library and run an incremental compile and have to wait 35 minutes on a Pentium 300 with 1/4 Gig of RAM for VC to tell me I have a syntax error and have to do it again.  Borland does the same compile ussually in under a minute and never more than 5.
0
 
LVL 3

Expert Comment

by:xyu
ID: 1170896
nietod: Yes You are right...but... i hed a chance to compare the Borland generated exe with VC one... (the same source code just different compilations) so i found as minimum 20% difference in real speed under Win32.... (in both cases optimizations was setted to speed , according to borland/microsoft recomendations)
and VC5 SP2 (not SP3) has much less hidden problems (like not calling the destructor if exception is thrown sometimes) than Borland... I'm still using borland to test compatibility of my source code and get some warnings that may be important... but I can't (unfortunately) tell that Borland C++ is the best compiler anymore....
0
 
LVL 22

Author Comment

by:nietod
ID: 1170897
xyu, specializing the entire class worked.  If nothing better comes along (and it probably won't until builder 4 comes along) I'll give you credit for that.
0
 
LVL 22

Author Comment

by:nietod
ID: 1170898
As to VC verses  Builder, I haven't made a decision on what is better for the final product.  The enourmous speed difference I see is in compile time (more than a factor of 10!)   In the final product, the builder code seems like it might be faster and it is smaller, but I don't trust it as being as solid.  I have found bugs in their library and have not in VC's.  The only reason I use builder in development is that I can compile faster.  However when it comes time for real debuging I have to switch back to VC and do a compile there.  But at least that way I don't have to wait 30 minutes for VC to tell me I have syntax errors and need to compile again.
0
 
LVL 3

Expert Comment

by:xyu
ID: 1170899
ok... but in my case i manage to change my project layout...to be compiled in acceptable time... with VC but, generally, You are absolutelly right
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:xyu
ID: 1170900
ok... but in my case i manage to change my project layout...to be compiled in acceptable time... with VC but, generally, You are absolutelly right
0
 
LVL 3

Expert Comment

by:xyu
ID: 1170901
ok... but in my case i manage to change my project layout...to be compiled in acceptable time... with VC but, generally, You are absolutelly right
0
 
LVL 22

Author Comment

by:nietod
ID: 1170902
I know I'm slow, but I got it the first time  : - )

How do these multiple posts happen anyways?  Some poeple seem to do it frequently and others not all
0
 
LVL 3

Expert Comment

by:xyu
ID: 1170903
ok... in my case it fault (multiple posts) of my proxy server... :(.. actually it may be caused by next scenario...

You answering or commenting... than Your brouser loading the result (next page) ... and You or Your proxy (intelligent :( ) sends refresh.... and reposts the form data :(.... that causes the multiply reposts...

0
 
LVL 3

Expert Comment

by:xyu
ID: 1170904
admins of EE have to change scrips to handle that problem ...
0
 
LVL 22

Author Comment

by:nietod
ID: 1170905
I've been here a year and there were old suggestions to fix it when I got here.  I don't know if you know this or not, but the EE staff, including programmers,  is entirely volunteer.  So improvements happen slowly.
0
 
LVL 22

Author Comment

by:nietod
ID: 1170906
xyu, I forgot about this.  I don't think anything other solutions are likely to be presented.  Why don't you answer and get your points.
0
 
LVL 3

Accepted Solution

by:
xyu earned 50 total points
ID: 1170907
nietod... ok this is my answer... meanwile if You'll look at natlib solution (it is nlcompat.h/nlcmptex.h/nlbc.h/nlmsc.h headers) it provides import/export/template expand tools that are work for BC 4.5/5.x and MSVC 5(SP2)/6(relase candidate)/6 compiler... it's checked....
Good luck
0
 
LVL 22

Author Comment

by:nietod
ID: 1170908
I was going to write you about that stuff you sent this weekend, but since you brought it up the day has been unusually productive...

First of all, do you still want me to look over those files?  if so what sort of things are you interested in?  I assume you are confidant in the basic implimentation.

Second of all, and this probably gets back to my original criticism, I have no clue how to use the stuff in those libraries that you suggested in your answer.  If I poor over the code I can probably figure it out, but I could write what I need faster.  That is why I said you needed better documentation.

By the way, did I respond to your last letter?  I was going away and kept putting it off, did I ever send anything?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now