mercredi 25 février 2015

Linker does not see template function defined in a base (pure virtual) class

Here's the code:



class PureDummy
{
public:
virtual void foo() = 0;
template<class T>
void bar();
};

class Dummy : public PureDummy
{
public:
virtual void foo()
{

}
template<class T>
void bar()
{

}
};

int main(int argc, char **argv)
{
PureDummy *pdummy = new Dummy();
pdummy->foo(); //OK
//pdummy->bar<int>(); //undefined reference to `void PureDummy::bar<int>()'
}


So as a comment states, with a call to bar compilation fails.




  1. Why does the template function exhibit different behavior from a "regular" foo function?




  2. Is it possible to "point" that there's an implementation in the derived class?




Aucun commentaire:

Enregistrer un commentaire