在类中使用模板的特征矩阵

发布于 2025-01-24 04:46:02 字数 695 浏览 4 评论 0原文

我想创建一个类,该类使用矩阵的类型和尺寸在构造函数调用过程中由用户确定的矩阵。我尝试使用一个类模板,然后将其参数用于实例化类成员中的所有内容,但我会遇到错误。

完成此操作的最佳方法是什么?

这是我的错误代码:

#pragma once
#include "Arduino.h"
#include "eigen.h"
#include <Eigen/LU>
#include <Eigen/Geometry>

using namespace Eigen;

template<typename type, static const int _numMeas, static const int _numStates>
class pf
{
public:
    pf(const Matrix<type, _numMeas, _numMeas>& _R, const Matrix<type, _numStates, _numStates>& _Q)
    {
    };

private:
    int numMeas   = _numMeas;
    int numStates = _numStates;

    Matrix<type, _numMeas, _numMeas> R;
    Matrix<type, _numStates, _numStates> Q;
};

I want to create a class that uses matrices whose types and sizes are determined by the user during the constructor call. I tried to use a class template whose arguments are then used to instantiate everything in the class members, but I'm getting errors.

What is the best way to accomplish this?

Here is my erroring code:

#pragma once
#include "Arduino.h"
#include "eigen.h"
#include <Eigen/LU>
#include <Eigen/Geometry>

using namespace Eigen;

template<typename type, static const int _numMeas, static const int _numStates>
class pf
{
public:
    pf(const Matrix<type, _numMeas, _numMeas>& _R, const Matrix<type, _numStates, _numStates>& _Q)
    {
    };

private:
    int numMeas   = _numMeas;
    int numStates = _numStates;

    Matrix<type, _numMeas, _numMeas> R;
    Matrix<type, _numStates, _numStates> Q;
};

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文