709394
09-06-2004, 08:51 PM
when I compile the program below, I got the following errors:
/tmp/cc8rlb0i.o(.text+0x18): In function `main':
: undefined reference to `A<int>::A[in-charge]()'
/tmp/cc8rlb0i.o(.text+0x27): In function `main':
: undefined reference to `A<int>::~A [in-charge]()'
collect2: ld returned 1 exit status
COMPILE CMD: g++ Main.cpp A.cpp -o a
Using g++ v3.3.1.
And if I put everything in 1 file, it compiles without any complaint.
Does someone knows what I did wrong?
thanx!
A.h
#ifndef _A_h
#define _A_h
template <class T>
class A
{
public:
/// Constructor
A();
/// Destructor
~A();
protected:
private:
};
#endif // _A_h
A.cpp
#include "A.h"
template <class T>
A<T>::A()
{
}
template <class T>
A<T>::~A()
{
}
Main.cpp
#include "A.h"
int main( void )
{
A<int> a;
return 0;
}
/tmp/cc8rlb0i.o(.text+0x18): In function `main':
: undefined reference to `A<int>::A[in-charge]()'
/tmp/cc8rlb0i.o(.text+0x27): In function `main':
: undefined reference to `A<int>::~A [in-charge]()'
collect2: ld returned 1 exit status
COMPILE CMD: g++ Main.cpp A.cpp -o a
Using g++ v3.3.1.
And if I put everything in 1 file, it compiles without any complaint.
Does someone knows what I did wrong?
thanx!
A.h
#ifndef _A_h
#define _A_h
template <class T>
class A
{
public:
/// Constructor
A();
/// Destructor
~A();
protected:
private:
};
#endif // _A_h
A.cpp
#include "A.h"
template <class T>
A<T>::A()
{
}
template <class T>
A<T>::~A()
{
}
Main.cpp
#include "A.h"
int main( void )
{
A<int> a;
return 0;
}