We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Template Specializaton in Builder 3

nietod
nietod asked
on
Medium Priority
313 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;
}
Comment
Watch Question

I think you syntax is correct and this is a compiler bug in Borland

Author

Commented:
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.  
xyu

Commented:
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 :(


Author

Commented:
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.
xyu

Commented:
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....

Author

Commented:
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.

Author

Commented:
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.
xyu

Commented:
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
xyu

Commented:
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
xyu

Commented:
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

Author

Commented:
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
xyu

Commented:
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...

xyu

Commented:
admins of EE have to change scrips to handle that problem ...

Author

Commented:
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.

Author

Commented:
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.
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
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?
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.