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

x
?
Solved

error C2440: '=' : cannot convert from 'double' to 'double *'

Posted on 2004-08-14
10
Medium Priority
?
2,436 Views
Last Modified: 2010-05-18
Hi
i am trying to square an array but i get this error ?
Can anyone please tell me how can i get rid of this
 error C2440: '=' : cannot convert from 'double' to 'double *'

// pointer to type "double"
double *S1;
then S1 has some values int he algo.
In the end i am trying to sqaure then i get this error .
this is the line giving errors : SquaredArray = S1[i] * S1[i] ;

iCe
0
Comment
Question by:iceb
[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
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11801851
Please post more code to detect exact error point. Apparently, you are trying to assign a double where you need a pointer to a double.
0
 
LVL 7

Expert Comment

by:JugglerW
ID: 11801906
What is squared array?
If it is also declared as

double* SquaredArray

your expression should be:

SquaredArray[i] = S1[i] * S1[i] ;

0
 
LVL 7

Expert Comment

by:JugglerW
ID: 11801918
This would explain the compiler message:

double* SquaredArray;
...
SquaredArray = S1[i] * S1[i]

Types are:
double* = double

So compiler says that it cannot convert a double ( right side) to a double* (left side)
0
Technology Partners: 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!

 
LVL 1

Author Comment

by:iceb
ID: 11801930
//JOKER is a specilaised pointer to type "DOUBLE"
   JOKER X1, Y1, Z1;

X1 = (JOKER) calloc(DATA, sizeof(DOUBLE));
Y1 = (JOKER) calloc(DATA, sizeof(DOUBLE));
Z1 = (JOKER) calloc(DATA, sizeof(DOUBLE));
Magnitude( --, --, --, &X1[i]);  This is a function where lots of parameters is being passed . Only the last parameter is shown and is the error giving parameter later in the code.

NOW I AM TRYING to do is square the array containing X[i]
Z[i] = (JOKERL) (X[i] * X[i]) /( Y[i] * Y[i]) ;          ERROR IN THIS LINE

error C2440: '=' : cannot convert from 'double' to 'double *'

thx for the prompt reply.

0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 11801969
What is JOKERL??

if it is double* also, it is a wrong cast. I think you could skip that and it will compile:

Z[i] =  (X[i] * X[i]) /( Y[i] * Y[i]) ;

Regards, Alex
0
 
LVL 1

Author Comment

by:iceb
ID: 11802002
JOKERL was a typo. it is JOKER.


NOW I AM TRYING to do is square the array containing X[i]
Z[i] = (JOKER) (X[i] * X[i]) /( Y[i] * Y[i]) ;          ERROR IN THIS LINE

error C2440: '=' : cannot convert from 'double' to 'double *'

thx for the prompt reply.
0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 2000 total points
ID: 11802059
The result of a division of doubles is a double and _NOT_ a double * .

Simply remove the cast (JOKER)

Regards, Alex
0
 
LVL 1

Author Comment

by:iceb
ID: 11802235
thx alex
there is no error now.
Before i close this question can you just explain one thing :
what is cast ?
i always get into problem trying to find out when to use and when not to use.
i am very confused about it.

thx again.
0
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 2000 total points
ID: 11802540
if you have

  x = (type)y;

than you try to 'cast' y to type 'type'.

e. g.

       int y = -1;
       unsigned int x = (unsigned int) y;

(x is now 0xffffffff).

In C mostly pointers get casted. For example the result of a call to malloc or calloc is a void pointer (no type). But as you need a pointer to double, int or any other type you have to cast it to the correct type.

In C++ normally you try to avoid casting as it unsafe(e.g. if you are casting a void pointer to a pointer type but the object isn't that type, you may get access  violation). When using 'new' instead of malloc/calloc you got a correct pointer and there is no need on a cast.

Regards, Alex
0
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 2000 total points
ID: 11802547
Your code from above without casts

X1 = new double[DATA];
Y1 = new double[DATA];
Z1 = new double[DATA];

NOW I AM TRYING to do is square the array containing X[i]
for (int i = 0; i < DATA; ++i)
    Z[i] = (X[i] * X[i]) /( Y[i] * Y[i]) ;  

Regards, Alex


0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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 …
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

670 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