Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Implicit instantiation of undefined template" when forward declaring template class

I've got some code in which I need to forward-declare the a template class (or at least, forward-declaring would make things a lot easier for me...). I've written a simplified version of the problem I'm having so I can display it here:

template<bool> class MyTemplateClass;  int main( int argc, char* argv[] ) {     MyTemplateClass<false> myTemp;  // error here     myTemp.GetTheValue();     return 0; }  template<bool bShouldMult> class MyTemplateClass {     int m_myint;     float m_myfloat;  public:     MyTemplateClass() : m_myint(5), m_myfloat(3.0f) {}     float GetTheValue()     {         return m_myint * (bShouldMult ? m_myfloat : 1.0f);     }     }; 

The error I'm getting at the commented line is:

Error - implicit instantiation of undefined template 'MyTemplateClass<false>' 

What other detail do I need to include in a forward declaration of MyTemplateClass? Since the error isn't coming from the next line down I'm assuming it isn't due to the fact that the method is undefined. The compiler I'm using is LLVM/CLang, and I'm compiling on Mac.

like image 941
benwad Avatar asked Oct 09 '12 09:10

benwad


1 Answers

Did you forget to #include something?

I got this after forgetting to

#include <array> 

When using a std::array

:^)

like image 162
kmiklas Avatar answered Sep 21 '22 21:09

kmiklas