Solved

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

Posted on 2004-08-14
10
2,337 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
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!

 
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 500 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 500 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 500 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

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!

Question has a verified solution.

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

Suggested Solutions

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…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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.

726 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