- template classes and .h file - 10 Updates
- cmsg cancel <d41ce2dc-9b04-489c-bb94-985027e3bbb9@googlegroups.com> - 3 Updates
- Trying to get better frequency distributions... - 1 Update
- The Miracle of Iron - 1 Update
- copy constructor and move constructor - 5 Updates
Rosario19 <Ros@invalid.invalid>: Sep 21 11:43AM +0200 On Sun, 20 Sep 2015 02:43:15 -0500, Paavo Helde wrote: >See also https://isocpp.org/wiki/faq/templates#templates-defn-vs-decl >hth >Paavo thank you but it is possible put only dichiarations [member, functions, operators etc] of the template class in the header file, and put all the code of that member functions, operators etc of the template class in the .dll file [in a way it is possible use that template class from some other .cpp file]? |
Rosario19 <Ros@invalid.invalid>: Sep 21 12:11PM +0200 On Mon, 21 Sep 2015 11:43:18 +0200, Rosario19 wrote: >the code of that member functions, operators etc of the template class >in the .dll file [in a way it is possible use that template class from >some other .cpp file]? it seems to me that this compile for the creation of the .dll but when i want to use the compiler on other .cpp file that call one instance of that template class... the compiler says "unrisolved external" even if i put __extern in the code of that template in the .dll so i would use only the .h file for template.... but doing so there could be problem in call functions expecially input/ output where their definitions, in the few i understand, are in one other file header afther, in include, the header where there is the template class |
Louis Krupp <lkrupp@nospam.pssw.com.invalid>: Sep 21 05:01AM -0600 On Mon, 21 Sep 2015 12:11:04 +0200, Rosario19 <Ros@invalid.invalid> wrote: >where their definitions, in the few i understand, are in one other >file header afther, in include, the header where there is the template >class If you could post two or three small files you're trying to compile (and possibly link) along with the errors you're getting, I think it would be helpful. Louis |
Paavo Helde <myfirstname@osa.pri.ee>: Sep 21 10:10AM -0500 Rosario19 <Ros@invalid.invalid> wrote in >>the code of that member functions, operators etc of the template class >>in the .dll file [in a way it is possible use that template class from >>some other .cpp file]? Yes, to some extent, via explicit instantiations. > the compiler says "unrisolved external" even if i put __extern in the > code of that template in the .dll > so i would use only the .h file for template.... Ok, fine. > where their definitions, in the few i understand, are in one other > file header afther, in include, the header where there is the template > class Template classes should be included first. Template definitions can access types and functions which are not yet declared, assuming that these types and functions depend on the template parameters. Such names are resolved in a later compilation stage, so there should be no problem. Example: template<class T> class Foo: public T{ public: int f() { return T::bar; // bar not yet declared, OK (as it depends on T) } }; class A { protected: const static int bar = 42; }; int main() { Foo<A> a; return a.f(); // ok } Note that leaving out T:: in f() would make the code invalid. hth Paavo |
Rosario19 <Ros@invalid.invalid>: Sep 21 07:18PM +0200 On Mon, 21 Sep 2015 05:01:13 -0600, Louis Krupp wrote: >(and possibly link) along with the errors you're getting, I think it >would be helpful. >Louis i think is not possible put code of the class template in the ndll.cpp file right? [pheraps only the code of the template not use type <T>] ----------------------- /* FILE ndll.cpp build the .dll and .lib usare: >bcc32 -v -WD ndll.cpp >implib ndll.lib ndll.dll */ #include "fileI.h" #include <stdio.h> #include <stdarg.h> int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved) {(void) hinst; (void) lpReserved; if(reason == DLL_PROCESS_ATTACH){} else if(reason == DLL_PROCESS_DETACH){} R 1; } int __export P(char* fmt, ... ) {va_list args; int r; va_start(args, fmt); r=vfprintf(stderr, fmt, args); va_end(args); R r; } template<class T> __export permutazioni<T>::permutazioni(u32 a) {u32 i; n=0; arr=0; c=0; cnt=0; ji=0; if(a==0||a>0xFF) {PBadAlloc=1; R;} arr=(T*)MM( a*S(T) ); if(arr==0){PBadAlloc=1; R;} c=(u32*)MM( a*S(u32) ); if(c==0){FF(arr); PBadAlloc=1; arr=0; R;} n=a; F(i=0; i<n; ++i){c[i]=0; arr[i]=i;} } template<class T> __export permutazioni<T>::~permutazioni(){FF(c); FF(arr);} template<class T> u32 __export permutazioni<T>::swp(T* a, u32 i, u32 j) {T x; if(i>=n||j>=n) R -1; if(i==j) R 0; x=a[i]; a[i]=a[j]; a[j]=x; ++cnt; R 0; } template<class T> u32 __export permutazioni<T>::index(T* a) {u32 r; if(arr==0||a==0) R -1; if( !(arr<=a&&a<arr+n) ) R -1; r=a-arr; if(r>0xFFFFFF) R -1; r=r/S(T); R r; } // b=a^-1 b[a]=I=1,2,3,4,5...n // a= 1 3 2 (1->1, 2->3 3->2) b= 1 3 2 // i->j j->i template<class T> i32 __export permutazioni<T>::inverse(permutazioni<T>& a) {u32 i; T t; if(arr==0||n!=a.n) R -1; // devono avere lo stesso n F(i=0; i<n; ++i) {t=a.arr[i]; if(!(0<=t&&t<n)) R -1; arr[t]= i ; // deve essere arr[a.arr[i]]=i; } nextP(0); // azzera next permutation } /* from Sedgewick, result in arr [3!=6] */ template<class T> u32 __export permutazioni<T>::nextP(u32 a) {u32 k; if(a==0) {F(k=0; k<n; ++k) c[k]=0; ji=0; cnt=0; R 1; } F( ; ji<n; ) {if(c[ji]<ji) {swp(arr, ((ji+1)%2? 0: c[ji]) , ji); ++c[ji]; ji=1; // can be ok ji=0; too R 1; // ok } else c[ji++]=0; } R 0; // for end } template<class T> i32 __export permutazioni<T>::e(void){R PBadAlloc;} template<class T> T& __export permutazioni<T>::operator[](i32 i){R arr[i];} template<class T> void __export permutazioni<T>::print(void) {u32 i; F(i=0; i<n; ++i) if(i==0 ) cout<<"[ "<< arr[i]<<" "; else if(i==n-1) cout<<arr[i]<<" ] "; else cout<<arr[i]<<" "; } ------------------------ /*FILE fileI.h */ #ifndef fileI #define fileI #ifndef fileII #include "fileII.h"
Subscribe to:
Post Comments (Atom)
|
No comments:
Post a Comment