Problem with pointer array

Hey Guys,
i've got a Problem with an Array of pointers.

First of all my classes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
struct sFace {
sPoint* points[2];        
sCell*  neighCells[2];
sFace*  neighFaces[4];

double* neighPe[4];
double* neighF[4];}

struct sCell {
   sFace*   faces[4];  
   sPoint*  points[4];
   sCell*   neighCells[4];
}

and
curFace = &data->faces[faceId];
curCell = &data->cells[cellId];


My first question is:
why i must not use the &-operator in
 
curFace->neighFaces[1]&= curFace->neighCells[1]->faces[1];

to assign the adress.

My second Question, is very similar:
in
 
curFace->neighPe[XP] = &curFace->neighFaces[XP]->Pe[0];


i have to use the &-Operator, but if i use it in
 
x=fabs(curFace->neighPe[XP]);

that it could'nt
'convert 'double*' to 'double' for argument '1' to 'double fabs(double)'

I hope that someone could help me
why i must not use the &-operator in
curFace->neighFaces[1]&= curFace->neighCells[1]->faces[1];

Because the &= is a bitwsie assignment operator https://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Compound_assignment_operators

My second Question, is very similar:
in curFace->neighPe[XP] = &curFace->neighFaces[XP]->Pe[0];

Here the & operator is used as reference operator, what means you take the address where curFace->neighFaces[XP]->Pe[0] is stored and saved in curFace->neighPe[XP] pointer.

i have to use the &-Operator, but if i use it in
x=fabs(curFace->neighPe[XP]);

Because curFace->neighPe[XP] is a pointer and fabs takes a value. So you need to pass to fabs the value of that pointer using the * operator.

x=fabs(*curFace->neighPe[XP]);

Example:

1
2
3
4
5
6
7
8
9
#include<cmath>
#include<iostream>
using namespace std;

int main(){
  double a=1;
  double*b=&a;
  cout<<fabs(*b)<<endl;
}

ncomputers.org
Last edited on
Topic archived. No new replies allowed.