0

Because I had to make a portable code, I decided from a Windows Console application generated with its associated main() within C++ Builder 5 (no vcl, but multithread)... Then, I defined a template class as :

template <class T = char, class U = T> class TPair;
 .... other definiions...
template <class T, class U> class TPair { TPair(const T &, const U &); 

                                          T A
                                          U B;
                                        };

Eveything is compiling fine... UNDER C++ BUILDER 5...

Going back to Borland C++ 5 (and NOT Builder), I can produce Win32 or Dos16 applications... There the compilation of the above code fails...

It clearly announces that "default parameters are not allowed in class definitions using templates"...

My large code heavily uses the default parameter in the declarations, so I can easily pass a parameter of (2 doubles) or (1 int and 1 double) using a simple declarations like TPair<double> or TPair<int, double>... instead of TPair<double, double> less readable...

Any workaround...?

  • 1
    Borland likely just doesn't support this, for better C++ support you'd need to look to open Watcom – Mgetz Apr 03 '22 at 12:57
  • 3
    I feel like I just stepped into a time machine. I guess I'd recommend starting work on a port to Visual Studio Community edition. I've done this with my old Borland C++ apps I have to maintain. It's a bit of work, especially in terms of GUI support (which Borland excelled at) but brings you into the 21st century in terms of language support. Other than that, you'll just have to refactor the code to avoid the default parameters. – lurker Apr 03 '22 at 13:15
  • 1
    Why do you need to write "portable" code that targets a compiler that is almost 30 years old? – Remy Lebeau Apr 03 '22 at 16:26
  • Why I do need "portable" ? Simply because I intend to have more than one terminal to connect to my server (many will be simple screens under Dos6.2 or Win311, while others will be under Win98, but supervisors of course will be with a WinForms interface)... Every version should be debuggable/recompilable on site. That's why we keep the Borland's line... Don't know much about Watcom, even if I come from the old school.... – David Harouche Apr 03 '22 at 17:24
  • Sure there are a lot of compilers that complies with actual C++ definitions... But they fail in continuum... About Visual Studio Community, one question... Will I take my code as is and compile it from C++Builder (console application) to Visual ? – David Harouche Apr 03 '22 at 17:24
  • 1
    @DavidHarouche [Open Watcom](https://github.com/open-watcom/open-watcom-v2) it should be able to do anything you need to do, support a _modernish_ toolchain and still support 16bit real mode code. – Mgetz Apr 03 '22 at 19:54
  • 1
    @DavidHarouche "*Will I take my code as is and compile it from C++Builder (console application) to Visual ?*" - depending on whether your code uses any Borland-specific functionality, it *may or may not* compile as-is. – Remy Lebeau Apr 03 '22 at 21:31
  • 1
    @DavidHarouche looks like you have a couple of options you can explore here that don't cost anything other than some of your time. You can try Open Watcom, and you can try Visual Studio Community edition and see how they go. – lurker Apr 03 '22 at 23:44
  • Many thanks for both approaches... I will keep my Borland Suite anyway... So I decided to define sub templates as TPairOfDouble when necessary... – David Harouche Apr 04 '22 at 08:40

0 Answers0