From: William Heymann Newsgroups: comp.os.msdos.djgpp Subject: Rhide and templates Date: Thu, 24 Apr 1997 17:11:59 -0400 Organization: University of Colorado at Boulder Lines: 86 Message-ID: <335FCC9F.5852@ucsu.Colorado.edu> Reply-To: heymann AT ucsu DOT Colorado DOT edu NNTP-Posting-Host: tele-anx0304.colorado.edu 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 am currently working on using a template in my program to make a dynamic 1 and 2 dimensional array of any type. Whenever I try to compile the program the program will compile but, when it tries to link the program into an executable I get unrecognized fuction errors for every single function that I have that is part of the template. I tried originally having two files a cpp and an h file but, when I changed it to a template it didn't work. I looked at some examples in some C++ books that I have and they had everything in the header file so I put everything in my header file also. This still did not work. Even the books example did not work. Is there a specific way that I have to include files to make them templates or some syntax that I am missing. Included below is a small example that shows the code for the 1D dynamic array. main.cpp #include "array.h" void main(void) { ARRAY temp(10); cout << "Width " << temp.Width() << endl; temp.Enter(10, 5); cout << "Result " << temp.Return(10) << endl; }; array.h #ifndef ARRAY_H #define ARRAY_H #include template class ARRAY { public: ARRAY(int width_); void Enter(int width_, Type c); Type Return(int width_); int Width(void); int Height(void); private: int width_; int height_; int width; int height; Type c; Type *array; }; template ARRAY::ARRAY(int width_) { width = width_; array = new Type [width]; assert(array != 0); } template void ARRAY::Enter(int width_, Type c) { array[width_ - 1] = c; } template Type ARRAY::Return(int width_) { return array[width_ - 1]; } template int ARRAY::Width(void) { return width; } #endif