Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
June 30th, 2013, 04:26 PM
 residentelvio
Contributing User

Join Date: May 2013
Posts: 56
Time spent in forums: 22 h 2 m 47 sec
Reputation Power: 0
Pointer to a vector of vectors

Do you know how to do it? I have an error:

#2
June 30th, 2013, 05:23 PM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,117
Time spent in forums: 1 Month 3 Weeks 2 Days 3 h 10 m 4 sec
Reputation Power: 455

If radius . front is a function, it isn't really. It could be a pointer to a function. Therefore, you ought to write

Since c will recognize what you mean, (*(radius.front))() probably returns a number. You want to take the address of a number?

__________________
[code]Code tags[/code] are essential for python code!

#3
June 30th, 2013, 06:03 PM
 residentelvio
Contributing User

Join Date: May 2013
Posts: 56
Time spent in forums: 22 h 2 m 47 sec
Reputation Power: 0
I m sorry I did not explain well. Googling it I see someone using this kind of code. I just need to know how assign a pointer to a vector of vector. Because I have en error.

#4
June 30th, 2013, 06:50 PM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,117
Time spent in forums: 1 Month 3 Weeks 2 Days 3 h 10 m 4 sec
Reputation Power: 455
If you wanted this in C++ you'll have to get someone else to explain the templates.
Code:
```/*
* compilation and example
*
* \$ a=./c && make -k \$a && \$a
* cc -Wall c.c -lm  -o c
* 2.71828 - 2.718 is 0.000281828
*/

#include<math.h>
#include<stdio.h>

/* f returns a pointer to a pointer */
double**f(void) {
static double x,*px;
x = 2.718;
px = &x;
return &px;
}

int main() {
double**ppx = f();
printf("%g - %g is %g\n", exp(1), **ppx, exp(1) - **ppx);
return 0;
}```

#5
June 30th, 2013, 07:42 PM
 residentelvio
Contributing User

Join Date: May 2013
Posts: 56
Time spent in forums: 22 h 2 m 47 sec
Reputation Power: 0
Glibc error

Hi people I have this error entering a function:
(really the error lines are more than this I put)

Code:
```*** glibc detected *** /home/elvio/workspace/aws/Debug/aws: double free or corruption (!prev): 0x0000000001eff100 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7eb96)[0x7f950c739b96]
/home/elvio/workspace/aws/Debug/aws[0x40afde]
/home/elvio/workspace/aws/Debug/aws[0x40a940]
/home/elvio/workspace/aws/Debug/aws[0x409f3b]
/home/elvio/workspace/aws/Debug/aws(_ZNSt6vectorId```

The function is : (I print Welcome to see in console I enter in the function)

Code:
```void pre_filter_Computations(vector< vector<double> > radius,vector< vector<double> > theta,int cols,int rows){

vector<double>x(cols);
vector<double>y(rows);
vector< vector<double> >X(cols, vector<double>(rows));
vector< vector<double> >Y(cols, vector<double>(rows));
double epsilon = 0.0001;

printf("welcome\n");

for(int i=0;i<cols;i++){
x[i]=((double)(i-cols)/2)/((double)cols/2);
}

for(int z=0;z<rows;z++){
y[z]=-(((double)(z-rows)/2)/((double)rows/2));
}

for(int m=0;m<cols;m++){
for(int n=0;n<rows;n++){

X[m][n]=x[m];
Y[m][n]=y[n];
}
}

for(int a=0;a<rows;a++){
for(int b=0;b<cols;b++){

X[a][b] = pow(X[a][b],2);
Y[a][b] = pow(Y[a][b],2);
X[a][b] = X[a][b] + Y[a][b];

}
}

for(int a=0;a<rows;a++){
for(int b=0;b<cols;b++){
theta[a][b] = atan2(Y[a][b],X[a][b])*180/PI;
}
}

}```

 Viewing: Dev Shed Forums > Programming Languages > C Programming > Pointer to a vector of vectors