Hi, I am having trouble compiling the simple code below...
//leader.hpp
#ifndef LEADER_HPP
#define LEADER_HPP
class leader
{
public:
leader(){}
virtual ~leader(){}
virtual void hahaha()=0;
virtual void hahahaha()=0;
};
#endif
//soldier.hpp
#ifndef SOLDIER_HPP
#define SOLDIER_HPP
#include "leader.hpp "
template <class T>
class soldier : public leader
{
public:
soldier(){}
virtual ~soldier(){}
virtual void hahaha();
virtual void hahahaha();
};
#endif
//soldier.cpp
#include "soldier.hp p"
template <class T>
void soldier<T>::hah aha()
{
}
template <class T>
void soldier<T>::hah ahaha()
{
}
// test.cpp
#include "leader.hpp "
#include "soldier.hp p"
int main(void)
{
leader *a;
a=new soldier<int>();
delete a;
return 0;
}
when I compile with g++, I get these errors:
g++ -o "test" test.o soldier.o
test.o:(.rodata ._ZTV7soldierIi E[vtable for soldier<int>]+0x10): undefined reference to `soldier<int>:: hahaha()'
test.o:(.rodata ._ZTV7soldierIi E[vtable for soldier<int>]+0x14): undefined reference to `soldier<int>:: hahahaha()'
collect2: ld returned 1 exit status
Is there something wrong with the code??
thanks,
sunny
//leader.hpp
#ifndef LEADER_HPP
#define LEADER_HPP
class leader
{
public:
leader(){}
virtual ~leader(){}
virtual void hahaha()=0;
virtual void hahahaha()=0;
};
#endif
//soldier.hpp
#ifndef SOLDIER_HPP
#define SOLDIER_HPP
#include "leader.hpp "
template <class T>
class soldier : public leader
{
public:
soldier(){}
virtual ~soldier(){}
virtual void hahaha();
virtual void hahahaha();
};
#endif
//soldier.cpp
#include "soldier.hp p"
template <class T>
void soldier<T>::hah aha()
{
}
template <class T>
void soldier<T>::hah ahaha()
{
}
// test.cpp
#include "leader.hpp "
#include "soldier.hp p"
int main(void)
{
leader *a;
a=new soldier<int>();
delete a;
return 0;
}
when I compile with g++, I get these errors:
g++ -o "test" test.o soldier.o
test.o:(.rodata ._ZTV7soldierIi E[vtable for soldier<int>]+0x10): undefined reference to `soldier<int>:: hahaha()'
test.o:(.rodata ._ZTV7soldierIi E[vtable for soldier<int>]+0x14): undefined reference to `soldier<int>:: hahahaha()'
collect2: ld returned 1 exit status
Is there something wrong with the code??
thanks,
sunny
Comment