How to pass a template class as a function argument without C7568 error

1.2k Views Asked by At

C++ newbie here. I'm pretty sure there's an easy and obvious solution to this problem, but even after reading through dozens of similar Q&As here, I haven't got closer to it. But here's my problem:

I have a template class:

template<class T>
struct KalmanSmoother
{
   Eigen::MatrixX<T> P;
   ...
   KalmanSmoother(int dynamParams, int measureParams, int controlParams = 0);
   ...
}

And I can use it without any problem, like this:

KalmanSmoother<float> smoother(4, 2);
smoother.P = Eigen::Matrix4f {
   {0.1f, 0.0f, 0.1f, 0.0f},
   {0.0f, 0.1f, 0.0f, 0.1f},
   {0.1f, 0.0f, 0.1f, 0.0f},
   {0.0f, 0.1f, 0.0f, 0.1f}
};
...

Works like charm. But when I want to refactor my code and I extract the initialization part into an other function, the compiler (MSVC 19.31.31104.0) starts crying. The function extraction looks like this:

// Declaration in the header:
void setupKalmanSmoother(KalmanSmoother<float> & smoother);

// Definition in the .cpp
inline void Vehicle::setupKalmanSmoother(KalmanSmoother<float> & smoother)
{
   smoother.P = Eigen::Matrix4f {
      {0.1f, 0.0f, 0.1f, 0.0f},
      {0.0f, 0.1f, 0.0f, 0.1f},
      {0.1f, 0.0f, 0.1f, 0.0f},
      {0.0f, 0.1f, 0.0f, 0.1f}
   };
   ...
}

And I'd just like to call it like this:

KalmanSmoother<float> smoother(4, 2);
setupKalmanSmoother(smoother);

Nothing magical. It should be working (I suppose...), but I get this compiler error:

error C7568: argument list missing after assumed function template 'KalmanSmoother'

The error message points to the declaration in the header. It's worth to mention that all function definitions of the template class are in the header file, since I have already run into - I think - exactly the same error when out of habit I put the definitions into the .cpp file.

So what am I missing?

Thanks in advance!!!

2

There are 2 best solutions below

0
szMuzzyA On

I ran into the same error when creating a datamember of a templated class.

    List<Graphics::RenderObject*> m_RenderObjects;

The fix in my instance was I needed to scope into the namespace that the 'List<>' was in.

    STD::List<Graphics::RenderObject*> m_RenderObjects;

Instead of saying 'List' is undefined, it gave me error 7568. Which is misleading. I recommend checking for similar issues.

0
Nick Deguillaume On

I got a very similar error. In my case it was due to circular #includes.