S
Steve
Sorry to be stupid, but I've been poring over TC++PL, and according to
what I see on page 351 (3rd ed.) the following code (split over three
files) should work. Instead, when I try to compile with g++ 3.3.3
(cygwin special), I get the following error. What am I doing wrong?
// the error: -----------------------------------------------
~/cpplib/tests[553] g++ template_test.cpp template_main.cpp
/c/DOCUME~1/SSCOTT~1.EDU/LOCALS~1/Temp/ccOJZwc5.o(.text+0x38):template_main.cpp:
undefined reference to `data<int>:rint()'
collect2: ld returned 1 exit status
//the code, first file: template_test.h
----------------------------------
#ifndef TTEST_H
#define TTEST_H
template <class T>
class data{
public:
T d;
data(T x): d(x){}
void print();
};
#endif //TTEST_H
// the code, second file: template_test.cpp
------------------------------
#include "template_test.h"
#include <iostream>
export template <class T>
void data<T>:rint(){
std::cout << d << std::endl;
}
// the code, third file: template_main.cpp
----------------------------------
#include "template_test.h"
int main(){
data<int> d(3);
d.print();
}
what I see on page 351 (3rd ed.) the following code (split over three
files) should work. Instead, when I try to compile with g++ 3.3.3
(cygwin special), I get the following error. What am I doing wrong?
// the error: -----------------------------------------------
~/cpplib/tests[553] g++ template_test.cpp template_main.cpp
/c/DOCUME~1/SSCOTT~1.EDU/LOCALS~1/Temp/ccOJZwc5.o(.text+0x38):template_main.cpp:
undefined reference to `data<int>:rint()'
collect2: ld returned 1 exit status
//the code, first file: template_test.h
----------------------------------
#ifndef TTEST_H
#define TTEST_H
template <class T>
class data{
public:
T d;
data(T x): d(x){}
void print();
};
#endif //TTEST_H
// the code, second file: template_test.cpp
------------------------------
#include "template_test.h"
#include <iostream>
export template <class T>
void data<T>:rint(){
std::cout << d << std::endl;
}
// the code, third file: template_main.cpp
----------------------------------
#include "template_test.h"
int main(){
data<int> d(3);
d.print();
}