Invalid types 'double*[double]' for array subscript

This is a discussion on Invalid types 'double*[double]' for array subscript within the C++ Programming forums, part of the General Programming Boards category; Hi people I have the error I named the question in the function: (With "here" I comment where the compiler ...

  1. #1
    Registered User
    Join Date
    Jun 2013
    Posts
    33

    Invalid types 'double*[double]' for array subscript

    Hi people I have the error I named the question in the function: (With "here" I comment where the compiler send me the error):

    Code:
    void ftshifting(matriz filter,int rows,int cols){ 
     
     double r2,c2,tmp1_3,tmp2_4; 
     r2 = (rows+1)/2;  c2 = (cols+1)/2;
    
     for (int i = 0; i<rows/2; i++){
       for (int k = 0; k<cols/2; k++){
           tmp1_3 = filter[i][k]; 
           filter[i][k] = filter[i+r2][k+c2];  //error
           filter[i+r2][k+c2] = tmp1_3;     //error
           tmp2_4 = filter[i+r2][k];          //error
           filter[i+r2][k] = filter[i][k+c2];  //error
           filter[i][k+c2] = tmp2_4;         //error
        } 
       }
    }
    
    double **createmat(int rows,int cols){ 
      double **m; 
      m=new double*[rows];
       for(int i=0;i<rows;i++) 
          m[i]=new double[cols]; 
     
    return m;
    }
    Code:
     
    The strange thing is that it worked before inserting the typedef double**matriz;
    I tested the function and it worked. Also, other function use this data and it works normally, example: (no errors at compiler time)

    Code:
    void pre_filter_Computations(matriz radius,matriz theta,int cols,int rows){ 
    
     double X[rows][cols],Y[rows][cols];
      double x[cols],y[rows];
     double epsilon = 0.0001;
     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]; 
        radius[a][b] = sqrt(X[a][b]); 
       }
           } 
         radius[rows/2][cols/2]=1;
          for(int a=0;a<rows;a++){
      for(int b=0;b<cols;b++){
        radius [a][b]= radius[a][b] + epsilon;
        theta[a][b] = atan2(Y[a][b],X[a][b])*180/PI; 
       } 
     }
    }

  2. #2
    Registered User
    Join Date
    Jun 2013
    Posts
    66
    Array subscripts must be of an integer type. Due to type promotions, when you add an integer and a double, the result type is double. This means that in for example
    Code:
    filter[i+r2][k+c2]
    i+r2 and k+c2 produce a double value and this represents a constraint violation in the compiler. You can fix it by casting the result or the double operand to int
    Code:
    filter[i + (int)r2][k + (int)c2]
    though the better approach is not to mix the types in the first place.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,918
    Why is it that you keep using pointers and dynamic memory when we've pointed out std::vector to you?
    Furthermore, PLEASE use std::vector's at function. There is no reason not you unless you can prove that it's a bottleneck. It's safer and it aids debugging.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. invalid types 'int[int]' for array subscript
    By kolistivra in forum C++ Programming
    Replies: 6
    Last Post: 12-11-2010, 12:57 PM
  2. Stupid error with long and double types
    By qmadd in forum C++ Programming
    Replies: 17
    Last Post: 08-23-2006, 11:45 AM
  3. urgent help!!arrays and float-double types...
    By philae in forum C Programming
    Replies: 14
    Last Post: 03-03-2006, 07:27 AM
  4. double/float data types
    By krygen in forum C++ Programming
    Replies: 6
    Last Post: 06-29-2004, 04:20 PM
  5. Changing double time to double cost
    By chrismax2 in forum C++ Programming
    Replies: 2
    Last Post: 04-24-2004, 11:29 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21