D
Dinakara
Hi,
I am programming with C++ using the gcc compiler.
Compiler : gcc version 3.4.3
OS : Red Hat 3.4.3-9.EL4.
I am not able to run the following program that declares a Template: Can
some body please help? There a total of three simple files whose contents,
which I have copied here.
//File 1 - MyTemplate.h
template < class T>
class MyTemplate
{
public:
MyTemplate();
};
//File 2 - MyTemplate.cpp
#include"MyTemplate.h"
template < class T>
MyTemplate<T>::MyTemplate()
{
cout<<"template Created"<<endl;
}
//File 3 - main.cpp
#include"MyTemplate.h"
#include <iostream>
using namespace std;
int main(void)
{
MyTemplate<int> oMytemplate;
}
1. This is how I am comiling the program : g++ main.cpp -o TemplateOut
This is the error I am getting : In function `main'::
undefined reference to `MyTemplate<int>::MyTemplate()', collect2: ld
returned 1 exit status
after taking a look at the gnu online docs,
http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_5.html#SEC110, I tried
compiling the code with g++ main.cpp -frepo -c -O. This created a Main.rpo
file that I do not know how to use.
All I want to see from this program is the line "template Created" to be
printed on the screen.
Thanks in advance.
- Dinakara.
I am programming with C++ using the gcc compiler.
Compiler : gcc version 3.4.3
OS : Red Hat 3.4.3-9.EL4.
I am not able to run the following program that declares a Template: Can
some body please help? There a total of three simple files whose contents,
which I have copied here.
//File 1 - MyTemplate.h
template < class T>
class MyTemplate
{
public:
MyTemplate();
};
//File 2 - MyTemplate.cpp
#include"MyTemplate.h"
template < class T>
MyTemplate<T>::MyTemplate()
{
cout<<"template Created"<<endl;
}
//File 3 - main.cpp
#include"MyTemplate.h"
#include <iostream>
using namespace std;
int main(void)
{
MyTemplate<int> oMytemplate;
}
1. This is how I am comiling the program : g++ main.cpp -o TemplateOut
This is the error I am getting : In function `main'::
undefined reference to `MyTemplate<int>::MyTemplate()', collect2: ld
returned 1 exit status
after taking a look at the gnu online docs,
http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_5.html#SEC110, I tried
compiling the code with g++ main.cpp -frepo -c -O. This created a Main.rpo
file that I do not know how to use.
All I want to see from this program is the line "template Created" to be
printed on the screen.
Thanks in advance.
- Dinakara.