How to split program into files- class c++

Question

Guys I'm bit confused now, I'm trying to split program into file.h file.cpp and main.cpp, here's example of my code:

//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.

};

I get the following errors:

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)

I know it won't work this way but I tried many other solution but without results, so thanks for any tips/advice for c++ a beginner.


Show source
| class   | matrix   | c++   | split   2017-01-01 22:01 1 Answers

Answers to How to split program into files- class c++ ( 1 )

  1. 2017-01-01 23:01

    When declaring the nested class outside of the containing class, you must use its full name class matrix::rcmatrix.

    Otherwise the compiler believes that you want to declare another, totally separate, class.

Leave a reply to - How to split program into files- class c++

◀ Go back