Posted by Computer Consultant on 1999-04-03
test<char *> t;
need that too.
At 07:45 PM 4/3/99 +0200, you wrote:
>Okay regarding my last post I have fixed it but only partially. The
>problem was in the makefile. But however it only works if I don't use
>templates in my C++ code.
>
>CC=g++
>OPS=-Wall -O2 -m486 -s
>
>test: main.o test.o
> $(CC) -o test main.o test.o $(OPS)
>
>main.o: main.cc
> $(CC) -c main.cc $(OPS)
>
>test.o: test.cc
> $(CC) -c test.cc $(OPS)
>
>clean:
> rm test *.o core
>
>
>However since this was a simple example it didn't really explain my
>current problem. I am using templates in another program and I want to
>compile it and link it similar to the example I provided. I modified the
>code I sent earlier to use templates and it no longer links cleanly. It
>complains about undefined references here is the modified code. It uses
>the makefile above
>
>// test.h
>#ifndef TEST_H
>#define TEST_H
>
>#include <iostream.h>
>
>template <class t>
>class test {
>
>public:
> test() {}
>
> void print(t a);
>
>};
>
>#endif
>
>// test.cc
>#include "test.h"
>
>template <class t>
>void test<t>::print(t a)
>{
> cout << a;
>}
>
>// main.cc
>#include "test.h"
>
>int main()
>{
> test t;
> t.print("hello,world\n");
>
>return 0;
>}
>
>
>--
>From: Frank Hale
>Email: frankhale@xxxxxxxx.xxx.xxx
>ICQ: 7205161
>Website: http://www.franksstuff.com
>
>
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=+
| http://www.nauticom.net/www/secret |
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=+
3%
Previous post | Next post | Timeline | Home