1

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!!!

  • No one's hopped in and answered yet, so I'm jumping to the assumption that it's not something trivial that you and I just aren't seeing. I recommend crafting a [mre] so we can poke at the problem. Maybe run it through a couple of other compilers to see if there's a difference or better compiler error. – user4581301 Feb 23 '22 at 18:45
  • @user4581301 Thanks! I'm gonna do that. – Attila Fenyvesi Feb 23 '22 at 18:59
  • "How to pass a template class as a function argument" has multiple problems, chiefly because it seems to mix templates, classes and objects. You instantiate a _class template_ to get a _class type_, and you instantiate a (class) _type_ to get an _object_. You can pass an object as a _function argument_. But here MSVC is talking about an argument to an assumed _function template_. That's weird; `KalmanSmoother` is a _class template_. (And it means the "argument" it's missing is a templat argument. Agree with @user4581301: we need a reproducible example. – MSalters Aug 26 '22 at 13:56
  • Also, as a trivial workaround: `KalmanSmoother smoother {4, 2};`. – MSalters Aug 26 '22 at 13:59
  • More fishy stuff: `// Definition in the .cpp inline void Vehicle::setupKalmanSmoother(KalmanSmoother & smoother)`. The `inline` in the .cpp is suspect, and suggests a lack of understanding what `inline` actually does (bypasses ODR). And `Vehicle::` means it's a class member function, yet the call `setupKalmanSmoother(smoother); shows no `Vehicle` object. – MSalters Aug 26 '22 at 14:01

2 Answers2

1

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

0

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.

szMuzzyA
  • 136
  • 13