Eclipse C :班级,名称空间,枚举找不到

Eclipse C++: class, namespace, enumeration not found

本文关键字:空间 枚举 找不到 班级 Eclipse      更新时间:2023-10-16

问候,预先感谢您!

我正在MacOS X 10.12工作;Eclipse Neon 4.6,使用MacOS X GCC编译。我收到以下错误:

../matrix.h:82:1: error: 'Matx' is not a class, namespace, or enumeration
`Matx::~matx(){`
`^`
`../matrix.h:27:7: note: 'Matx' declared here`

由于以下matrix.h文件,错误令人困惑:

#ifndef MATRIX_H_
#define MATRIX_H_
#include <iostream>
template <class T>
class Matx {
    int ROWS, COLS ;
    int colix[COLS], rowix[ROWS] ;
    T ** array ;
    Matx(int, int) ;
    ~Matx() ;
    void rowSwap() ;
    void size( void ) ;
    void swapRows(int i1, int i2) { std::swap(this->array[i1], this->array[i2]); }
    void printMat( void ) ;

};// end class matrix
template <class T>
Matx::~Matx(){
    delete this->array ;
}// end ~matx()

请注意,文件中还有更多功能,但是所有这些功能在所有功能中都是一致的。我尝试使用范围分辨率定义功能,没有Matx::~m,但无济于事。任何帮助都非常感谢!

您应该像这样编写函数的定义:

template <class T>
Matx<T>::~Matx(){
    delete this->array ;
}// end ~matx()

此部分是错误的。

int ROWS, COLS ;
int colix[COLS], rowix[ROWS] ;

您定义了大小col和行的阵列。但是这些是非CONST成员变量。您需要编译时间表达式。例如:

static constexpr int ROWS = 4;
static constexpr int COLS = 4;