Solved

complex number

Posted on 1999-01-24
3
272 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 31

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 31

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

751 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