E2108 Improper use of typedef 'CMatrix'

Hi everyone,
I am trying to write a function modulation which return complex matrix.

Unfortunately during compilation I get error:

[C++ Error] fSTCoding_Decoding.cpp(89): E2108 Improper use of typedef 'CMatrix'
[C++ Error] fSTCoding_Decoding.cpp(89): E2379 Statement missing ;


I can not find where is the problem.

I appended source code maybe someone will find mistake.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
double Es;             
CMatrix mod_symbol;   
int symbol_number;  

CMatrix modulation(double Eb,int modulation_type) //line(89)
{
        if(modulation_type==1)      //BPSK
                {
                symbol_number=post_bit_number;
                mod_symbol.SetSize(1,symbol_number);
                Es=Eb;
                for(int j=0;j<symbol_number;j++)
                        {
                        if(info_source(0,j)==0)
                                {
                                mod_symbol(0,j).real()=-sqrt(Es);
                                mod_symbol(0,j).imag()=0;
                                }
                        else
                                {
                                mod_symbol(0,j).real()=sqrt(Es);
                                mod_symbol(0,j).imag()=0;
                                }
                        }
                }
         else if(modulation_type==2) //QPSK
                {
                ...
                }
         else   //16-QAM
                {
                ...
                }
return(mod_symbol);
}

Few additional info which could be helpful:

This is what I have to include in source code to work with matrix class:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include "matrix.h" 

#ifndef _NO_NAMESPACE
using namespace std;
using namespace math;
#define STD std
#else
#define STD
#endif

#ifndef _NO_TEMPLATE
typedef matrix<double> Matrix;      
#else
typedef matrix Matrix;
#endif

typedef complex<double> type;
typedef matrix<type> CMatrix;     


I am using Matrix TCL Lite class by http://www.techsoftpl.com/

Thank You in advance
What is type in typedef matrix<type> CMatrix;?
I think it is auxiliary complex double data type used as CMatrix's entity's entry's data type.
By this I mean when I declare matrix CMatrix mod_symbol, its entries will have typevalues (complex and double).

I am beginner in programming and don't actually know why it is done in this way, but when I download examples for using matrix.h class from http://www.techsoftpl.com/ I noticed that in those examples it works.

One of these is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//////////////////////////////////////////////////////
// File: MatDemo2.cpp
// Copyright (c) 1997-2002 Techsoft Private Limited
// Purpose: Demonstrates how to use Matrix TCL Lite v1.13
// Web: http://www.techsoftpl.com/matrix/
// Email: matrix@techsoftpl.com
//

#include "matrix.h"

////////////////////////////////
// Note: The following conditional compilation statements are included
//       so that you can (likely to) compile this sample, without any 
//       modification, using a compiler which does not support any or 
//       all of the ANSI C++ features like NAMEPACE, TEMPLATE, and 
//       EXCEPTION, used in this class.
//
//       If you have a compiler, such as C++ Builder, Borland C++ 5.0,
//       MS Visual C++ 5.0 or higher, etc., which supports most of the ANSI 
//       C++ features used in this class, you do not need to include these
//       statements in your program.
//
#ifndef _NO_NAMESPACE 
using namespace std;
using namespace math;
#define STD std
#else
#define STD
#endif
 
#if !defined(_NO_TEMPLATE)
#  if defined(_MSC_VER)
#     if _MSC_VER > 1000
#        include <complex>
         typedef complex<double> type;
#     else
         typedef double type;
#     endif
#  elif defined(__BORLANDC__)
#     if defined(__WIN32__)
#        include <complex>
         typedef complex<double> type;
#     else
#        include <complex.h>
         typedef complex type;
#     endif         
#  elif defined( __GNUG__ ) 
#       include <complex>
        typedef complex<double> type;
# elif defined( _SGI_BROKEN_STL )
# include <complex>
typedef std::complex<double> type;
#  endif
  typedef matrix<type> Matrix;
#else
   typedef matrix Matrix;
#endif

#ifndef _NO_EXCEPTION
#  define TRYBEGIN()	try {
#  define CATCHERROR()	} catch (const STD::exception& e) { \
                     cerr << "Error: " << e.what() << endl; }
#else
#  define TRYBEGIN()
#  define CATCHERROR()
#endif


int main ()
{
   Matrix m(3,3),v(3,1),s(3,1);

   cout << "Solution of linear equations of complex number:\n\n";
   cout << "Enter the linear equations as (3x3) matrix:\n";
   cin >> m;
   cout << "Enter the vector as (3x1) matrix to solve it:\n";
   cin >> v;

   TRYBEGIN()
   {
     s = m.Solve(v);
   }
   CATCHERROR();

   cout << "Solution:\n" << s << endl;

   return 0;
}


To distinguish real value matrix type from complex value, I named in my code the first one by Matrix and the second by CMatrix.

I am using Borland Builder v6.
The point is type needs to be known when you do
typedef matrix<type> CMatrix;

If it remains unknown, you can't use it yet.
Hmm,
I have written simple application and
typedef complex<double> type;
typedef matrix<type> CMatrix;
work fine in it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "fCMatrix.h"
#include <complex.h>
#include <fstream.h>
/////////////////////////////////MATRIX/////////////////////////////////////////////////////////
#include "matrix.h"

#ifndef _NO_NAMESPACE
using namespace std;
using namespace math;
#define STD std
#else
#define STD
#endif

#ifndef _NO_TEMPLATE
typedef matrix<double> Matrix;
#else
typedef matrix Matrix;
#endif
typedef complex<double> type;
typedef matrix<type> CMatrix;
//////////////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{

CMatrix matrix_1(1,4);
for(int i=0;i<4;i++)
        {
         matrix_1(0,i)=complex<double>(2.7,5.4);
        }
ofstream Matrix_example_file;
Matrix_example_file.open ("Matrix.txt");
for(int i=0;i<4;i++)
        {
        Matrix_example_file<<matrix_1(0,i)<<"\n";
        }
Matrix_example_file.close();
}
//--------------------------------------------------------------------------- 


In that example, type is complex<double>. We can see it; the compiler can see it.

But in the problem code that you posted to begin with type is undefined. That's what the problem is.
Generally I don't see difference between this example and the problematic code.

Can You explain wider why in example
type
is defined and in problematic code is not?

I changed a little example code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
void __fastcall TForm1::Button1Click(TObject *Sender)
{

CMatrix matrix_1(1,4);

CMatrix out_matrix()
{
for(int i=0;i<4;i++)
        {
         matrix_1(0,i)=complex<double>(2.7,5.4);
        }
return(matrix_1)
}
ofstream Matrix_example_file;
Matrix_example_file.open ("Matrix.txt");
for(int i=0;i<4;i++)
        {
        Matrix_example_file<<matrix_1(0,i)<<"\n";
        }
Matrix_example_file.close();

}


and error
E2108 Improper use of typedef 'CMatrix'
occurred one more time in line 7.

I noticed that it happen when I define function returning complex matrix but don't know why and how to fix it.
In the example that works, type is defined with:
typedef complex<double> type;
It's defined to be complex<double>

But your original post that does not work, you provided no definition for the name type. If you think you have, can you post it please.
I have modified example code (added function out_matrix())to show the same situation as in problematic code at the begging of topic.

In problematic code I have also function modulation() which give Error E2108 and was also written as a reaction on OnButtonClick event.
You haven't answered the question about the declaration of type.
I misunderstood what You ask me for.
I haven't declare type .
That's the error.
How to declare it e.g in my example code?
What type of number do you want in your matrix, int, double, complex<double>?
complex<double>
Topic archived. No new replies allowed.