Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/156.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 模板矩阵<;M、 N,类型>;c++;矩阵乘法_C++_Templates - Fatal编程技术网

C++ 模板矩阵<;M、 N,类型>;c++;矩阵乘法

C++ 模板矩阵<;M、 N,类型>;c++;矩阵乘法,c++,templates,C++,Templates,我在另一篇文章中得到了关于使用模板抽象类重写的帮助,多亏了社区,我才使它工作得很好。既然那篇文章的问题已经不存在了,我要问一个新问题: 我想实现乘法,所以我需要不同的模板参数使其工作(行数=列数条件),但我无法找到正确的方法 #pragma once #include "AbsMatrice.h" template <int M, int N, typename T> class Matrice : public AbsMatrice<M,N,T> { public

我在另一篇文章中得到了关于使用模板抽象类重写的帮助,多亏了社区,我才使它工作得很好。既然那篇文章的问题已经不存在了,我要问一个新问题:

我想实现乘法,所以我需要不同的模板参数使其工作(行数=列数条件),但我无法找到正确的方法

#pragma once
#include "AbsMatrice.h"

template <int M, int N, typename T>

class Matrice : public AbsMatrice<M,N,T>
{

public:
    ~Matrice(){}

    //implementation de l'affichage
    void print() const  override
    {
        std::cout << "Matrice :" << std::endl;

        for (int i = 0; i < M; i++)
        {
            for (int j = 0; j < N; j++)
            {
                std::cout << " " << this->m_data[i][j] << " ";
            }
            std::cout << std::endl;
        }
    }

    template<int O>
    Matrice<M, O, T>& mul(Matrice<N, O, T> &a) 
    {
        Matrice<M,O,T> r;
        T sum;
        for (int c = 0; c < M; c++) {
            for (int d = 0; d < O; d++) {
                for (int k = 0; k < N; k++) {
                    sum = sum + m_data[c][k] * a(k,d);
                }

                r(c,d) = sum;
                sum = 0;
            }
        }

        return r;
    }


};
#pragma一次
#包括“AbsMatrice.h”
模板
类矩阵:公共矩阵
{
公众:
~Matrice(){}
//实施法
void print()常量重写
{
std::cout我看到了几个问题:

您的问题的答案是您不想返回
*r
,您只想返回
r

第二个问题是
r
应该是
Matrice
类型。因为它是当前矩阵的类型。

我看到了几个问题:

您的问题的答案是您不想返回
*r
,您只想返回
r

第二个问题是,
r
应该是
Matrice
类型。因为它是当前矩阵的类型

error C2100: illegal indirection
see reference to function template instantiation 'Matrice<2,2,int> &Matrice<2,2,int>::mul<2>(Matrice<2,2,int> &)' being compiled