A
arun
Hello team,
I know that
extern keyword before template class or function delays the
instantiation of that template
declaration.
However,, my question is does this utility only works for creating the
libraries or can I use
this utility without using any libraries.
For example I have three files.
queue.h
one.cc
two.cc
queue.h
******************
template <class T> class Queue {
public:
Queue() {}
~Queue() {}
T t;
};
extern template class Queue<int>;
*******************************
one.cc looks like
*****************
#include "queue.h"
int set(Queue<int> q) {
return q.t;
}
******************
and two.cc looks like
*******************
using namespace std;
#include <iostream.h>
#include "queue.h"
int main(void) {
Queue<int> q;
int a = set(q);
cout <<"The value of a is " << a << endl;
return 0;
}
******************
The whole code does not compile and I get following error by compiler.
********
undefined referenct to Queue<int>::Queue()
undefined referenct to Queue<int>::~Queue()
in function main.
**********
Kindly tell me what am I doing wrong.
Thanks.
arun
I know that
extern keyword before template class or function delays the
instantiation of that template
declaration.
However,, my question is does this utility only works for creating the
libraries or can I use
this utility without using any libraries.
For example I have three files.
queue.h
one.cc
two.cc
queue.h
******************
template <class T> class Queue {
public:
Queue() {}
~Queue() {}
T t;
};
extern template class Queue<int>;
*******************************
one.cc looks like
*****************
#include "queue.h"
int set(Queue<int> q) {
return q.t;
}
******************
and two.cc looks like
*******************
using namespace std;
#include <iostream.h>
#include "queue.h"
int main(void) {
Queue<int> q;
int a = set(q);
cout <<"The value of a is " << a << endl;
return 0;
}
******************
The whole code does not compile and I get following error by compiler.
********
undefined referenct to Queue<int>::Queue()
undefined referenct to Queue<int>::~Queue()
in function main.
**********
Kindly tell me what am I doing wrong.
Thanks.
arun