🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.migration
Article #98

templates works with BC5 but not with BCB6

#98
From: YAZ
Date: Wed, 08 Jun 2005 11:06
165 lines
4185 bytes
Hello,
I'm trying to use a static library compiled with BCB5 with a new
project in BCB6.
I got unresolved external so I recompiled the library with BCB6. the
library compiles with no errors in BCB6. but when linking it to my
project i got unresolved external too.


The library is very big so I made an example that explains the problem
(bug !). The problem seems to come from non-type "template <>".


===================header.h===­============


#if   (LIB_TYPE==0)
#define my_type     double
#elif (LIB_TYPE==1)
#define my_type     int
#endif


#include <assert.h>
#include <stdio.h>
#include <stdlib.h>


template <class T>class A;


template <class T>class A {
public:
  T* p;
  int n;
  A();
  int function1(); //implemented in unit1.cpp
  //it calls function2 implemented in unit2.cpp
 };


typedef A<my_type>        A_my_type;


template class A<double>;
template class A< A<double> >;
template class A<int>;
template class A< A<int> >;


int function2(my_type* ptr, int n);
A<my_type> func3(A<my_type> x); // function in the library i want to
use


=============Unit1.cpp========­=============
#include "header.h"


template <class T>A<T>::A() {
p=NULL;
n=0;


}


//unresolved ???
template <> int A<my_type>::function1() {
if (!function2(p,n)) {
p=NULL;


}
return p!=NULL;
}


template <> int A< A<my_type> >::function1() {
return 0;

}


==============Unit2.cpp=======­===============
#include "header.h"

int function2(my_type* ptr, int n) {
if (ptr==NULL) {
return 0;


}


while ( ( n && (*ptr)==0.0 ) ) {
n--;
ptr++;


}
return (n>0);
}


int function2(A<my_type> x) {
  return x.function1();

}


int function2(A<A_my_type> ) {
return 0;


}


A<my_type> func3(A<my_type> x) {
x.function1();
return x;

}


==============tst1.cpp========­=======
#include "header.h"
int main()
{
A<double> a,b;
b=func3(a);

}


==============================­========
I compile unit1 & unit2 and i try to link with
J:\CBuilder6\work\templates>bc­c32 -P  -DLIB_TYPE=0 -c unit1.cpp
Borland C++ 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland
unit1.cpp:

J:\CBuilder6\work\templates>bc­c32 -P  -DLIB_TYPE=0 -c unit2.cpp
Borland C++ 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland
unit2.cpp:


J:\CBuilder6\work\templates>bc­c32 tst1.cpp unit1.obj unit2.obj
Borland C++ 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland
tst1.cpp:
Turbo Incremental Link 5.64 Copyright (c) 1997-2002 Borland
Error: Unresolved external 'A<double>::function1()' referenced from
J:\CBUILDER6\WORK\TEMPLATES\UN­IT2.OBJ


With BCB5 the code compiles & links fine !!


Can u please tell me if it's a bug or not. 


thanks
Technical Details
Message-ID: <1118228765.521562.224730@g14g2000cwa.googlegroups.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!g14g2000cwa.googlegroups.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 110f51,b84d0e391cfe0a6f,start
X-Google-Attributes: gid110f51,public
X-Google-Language: ENGLISH,ASCII
Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!g14g2000cwa.googlegroups.com!not-for-mail
From: "YAZ" <abiradla@hotmail.com>
Newsgroups: borland.public.cppbuilder.migration
Subject: templates works with BC5 but not with BCB6
Date: 8 Jun 2005 04:06:05 -0700
Organization: http://groups.google.com
Lines: 166
Message-ID: <1118228765.521562.224730@g14g2000cwa.googlegroups.com>
NNTP-Posting-Host: 212.194.99.103
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1118228773 26313 127.0.0.1 (8 Jun 2005 11:06:13 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Wed, 8 Jun 2005 11:06:13 +0000 (UTC)
User-Agent: G2/0.2
Complaints-To: groups-abuse@google.com
Injection-Info: g14g2000cwa.googlegroups.com; posting-host=212.194.99.103;
   posting-account=PpmHHQwAAAAw-LtpQUnP_pOFyxWsoiu_