Link to home
Start Free TrialLog in
Avatar of deuter
deuter

asked on

complex number

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.
ASKER CERTIFIED SOLUTION
Avatar of Zoppo
Zoppo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of deuter
deuter

ASKER

zoppo, thanks for the explanation, can you show me where i can get more info for the template?
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