Solved

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

Posted on 2004-08-14
10
2,314 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
  • 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
maze travler 6 62
FMX TCameraComponent Problem 2 84
Copy output image from TWindowsMediaPlayer 6 48
How to convert Structure to vector of byte and vice versa 5 24
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

828 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