Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

templates works with BCB5 but not with BCB6 !!

0 views
Skip to first unread message

YAZ

unread,
Jun 8, 2005, 7:08:15 AM6/8/05
to
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

0 new messages