Solved

complex number

Posted on 1999-01-24
3
261 Views
Last Modified: 2010-04-02
this question goes out t othose who have experience in BCB3.
recently, i tried to used the complex class in a SDI application. i declared a variable like this:

#include <complex.h>
complex EM;

the complier gave an error message :"illegal use of template."
Whats wrong ?
can someone pls explained.
0
Comment
Question by:deuter
  • 2
3 Comments
 
LVL 30

Accepted Solution

by:
Zoppo earned 100 total points
ID: 1185041
I do not know BCB3, but I know that complex is a template class needing a type as parameter like this:

#include <complex.h>
complex <float> EM;   // create a complex using floats
complex <double> EM_1;   // create a complex using doubles

Explanation:
copmlex is defined as template like this:
------------------------------------------------------------
template<class T> class complex
{
    public:    typedef T value_type;
// and so on ...
------------------------------------------------------------
This tells the compiler to create a own class complex for any type with which it's used (thats the sense of templates).

so you must declare the type !!


hope that help,

ZOPPO
0
 

Author Comment

by:deuter
ID: 1185042
zoppo, thanks for the explanation, can you show me where i can get more info for the template?
0
 
LVL 30

Expert Comment

by:Zoppo
ID: 1185043
I think you just will have to buy a good C++ book to learn more about templates. I can give you a short description:

the expression 'template <class T(,...)>' before a class or function definition tells the compiler to create one class/function for each different type used.

For example:

template <class T> class X // example of a simple template class X
{
public:
typedef T calue_type;

value_type m_data;
void SetData( value_type data ) { m_data = data };
value_type GetData( void ){ return m_data };
.
}

template <class T> T mymin( T w1, T w2 ) // template function mymin
{
if ( w1 < w2 )
   return w1;
else
   return w2;
}

X<char> x_char;               // creates a class X with value_type char
X<double> x_double;        // creates a class X with value_type double
X<CString> x_string;        // creates a class X with value_type CString

int i = mymin( 5, 3 );        // create a call to a funtion 'int mymin( int 5, int 3 );' - returns 3
double d = mymin( 5.3, 7.4 );      // create a call to a funtion 'double mymin( double, double );' - returns 5.2
CString test = mymin( "world", "Hello, " );  // create a call to a funtion CString mymin( CString, CString );' - returns "Hello, world"

that not a good explanaition, but it's all I ever needed to know. But allthough I think it's good to have a good C++ book to learn this more detailed.

hope that helps,

ZOPPO
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now