From: somjen AT netvision DOT net DOT il (Ohad Somjen) Newsgroups: comp.os.msdos.djgpp Subject: templates and djgpp - Mat.err (0/1) Date: Mon, 01 Sep 1997 04:30:57 GMT Organization: NetVision LTD. Lines: 112 Message-ID: <340a3dd2.114729@news.netvision.net.il> NNTP-Posting-Host: ts002p5.pop8a.netvision.net.il Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk i'm a student and just for practice i want to write a template class for vectors and matrices. it's been a while since i coded so i just remembered that all the code has to be in the header file, but this does nt seem to work becuase is have an internal variable that causes an error. here is some code: i had so many errors when i implemented the functions outside that i gave up and inserted them into the class declaration. template class vector { private: T* vec; int size; char dir; public: vector(int s,char d='h') { dir=d; vec=new T[s]; if (!vec) { cout << "could not allocate vector" << endl; } } vector(int s,T& t,char d='h') { dir=d; vec=new T[s]; if (!vec) { cout << "could not allocate vector" << endl; } for(int i=0;isize;i++) vec[i]+=v.vec[i]; else cout << "vector size do not match" << endl; return *this } vector& operator+(const vector& v) { vector temp; if(size==v.size) for(int i=0;i>size;i++) temp.vec[i]=vec[i]+v.vec[i]; else cout << "vector size do not match" << endl; return temp; } T& scalar(const vector& u,const vector& v) { T temp=0; if((u.dir!=v.dir) && (u.size==v.size)) for(int i=0,i A(4,'h') vector B(4,'v'); return 0; } and when i compile i get a parse error before the '(' of main then data template 'class vector B' must be member of a class template. then assignment (not initialization) in declaration and bailing out. attached is the output of gcc for this compilation.