Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

complex number

Posted on 1999-01-24
3
Medium Priority
?
275 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 400 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

  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 …
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 use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

715 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