Solved

complex number

Posted on 1999-01-24
3
267 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 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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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 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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

803 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