Zingam
18th April 2011, 07:25
Hi, I'm trying to learn more about templates but stumbled upon something I do not understand.
I have declared an abstract class that starts like that:
template<class T>
class StackBase
{
public:
StackBase(){};
virtual void push(const T& x) = 0;
Then I have this:
template<class T>
class StackArray : public StackBase<T>
{
public:
StackArray(){std::cout << "OK! Constructed!\n";};
void push(const T& x){};
...and now I use it:
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
StackArray<char> sac;
sac.pop();
(Plz. note that's not a finished class at all).
Then I've found out that if I change any of the templated classes (if I change any of the files) and if I just "Build" all I get is a linker error of unspecified StackArray();
I have to do "Rebuild" (or "Clean" and "Build") to make it compile and link.
Am I doing something wrong here? Is that how it is supposed to be? Does it mean that I have to do a full rebuild everytime I'm working with templates even if it is a large project that takes an hour to compile.
I have declared an abstract class that starts like that:
template<class T>
class StackBase
{
public:
StackBase(){};
virtual void push(const T& x) = 0;
Then I have this:
template<class T>
class StackArray : public StackBase<T>
{
public:
StackArray(){std::cout << "OK! Constructed!\n";};
void push(const T& x){};
...and now I use it:
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
StackArray<char> sac;
sac.pop();
(Plz. note that's not a finished class at all).
Then I've found out that if I change any of the templated classes (if I change any of the files) and if I just "Build" all I get is a linker error of unspecified StackArray();
I have to do "Rebuild" (or "Clean" and "Build") to make it compile and link.
Am I doing something wrong here? Is that how it is supposed to be? Does it mean that I have to do a full rebuild everytime I'm working with templates even if it is a large project that takes an hour to compile.