【问题标题】:How to split program into files- class c++如何将程序拆分为文件 - 类 c++
【发布时间】:2017-01-01 21:54:49
【问题描述】:

伙计们,我现在有点困惑,我正在尝试将程序拆分为 file.h file.cpp 和 main.cpp,这是我的代码示例:

//file.h//

class matrix
{
   private:
      class rcmatrix;
      rcmatrix *data;

   public:
     class Cref;
     class Size_Check{};
     matrix();
    ~matrix();
     matrix(const int rows, const int cols, const double num);
};

class rcmatrix
{
    private:
      rcmatrix(const rcmatrix&);
      rcmatrix &operator =(const rcmatrix&);

    public:
      int rows;
      int cols;
      double **mat;
      int n;
      rcmatrix();
     ~rcmatrix();
};

//file.cpp

matrix::rcmatrix::rcmatrix()
{
    rows=0;
    cols=0;
    mat=NULL;
    n=1;
};
matrix::rcmatrix::rcmatrix(const int r, const int c, const double num)
{
    //instructions.

};

我收到以下错误:

error: invalid use of incomplete type ‘class matrix::rcmatrix’

error: ‘class matrix::rcmatrix’ is private

error: expected unqualified-id before ‘const’
matrix::rcmatrix(const int r, const int c, const double num)

我知道它不会以这种方式工作,但我尝试了许多其他解决方案但没有结果,因此感谢 C++ 初学者的任何提示/建议。

【问题讨论】:

  • (a) 您是否已经将程序放在一个大文件中,然后尝试拆分它,还是已经拆分? (b) 错误发生在哪几行?

标签: c++ class matrix split


【解决方案1】:

在包含类之外声明嵌套类时,必须使用其全名class matrix::rcmatrix

否则编译器认为你想要声明另一个完全独立的类。

【讨论】:

  • 好的,谢谢,但是你能告诉我第三个错误有什么问题吗?
猜你喜欢
  • 2021-12-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-03
  • 1970-01-01
  • 2014-07-15
  • 1970-01-01
  • 2015-03-29
相关资源
最近更新 更多