I'm writing a small piece of code finding the number of unique 3D arrays in a N*3 array.
I first sort the N*3 array, and apply a "condition" function : if the consecutive 3D arrays do not have the same element, then the unique number count +1.
Here is the code:

#include <iostream>
using namespace std;

int condition(double **A, int index, int col);
int unique_multiD(double** list, int xcol, int ycol);
int main()
    double data[][3] = {{1,2,3},{2,3,2},{3,2,1},{3,2,1},{1,3,2},{3,2,3},{3,2,1},{3,2,3}};

// -- main function ----
    const int ycol = sizeof(data[0])/sizeof(data[0][0]);
    const int xcol = sizeof(data)/sizeof(data[0]);
    int unique = 0;
    double **list = new double*[xcol];
    for(int i = 0; i < xcol; i++) list[i] = new double[ycol];
    for(int i = 0; i < xcol; i++) list[i] = &data[i][0];

    unique = unique_multiD(list,xcol,ycol);

    cout << "unique number = " << unique << endl;
// -- ||| main function ends ----------|||
    return 0;

int condition(double **A, int index, int ycol){//to determine if A[index] is unique
    int unique = 0;

    for(int i = 0; i < ycol; i++)
        if(A[index][i] != A[index+1][i]) unique++;

    if(unique != 0) unique = 1;
    return unique;

int unique_multiD(double** list, int xcol, int ycol)//sort the array and identify unique values
    double* extemp = new double[3];
//-- sorting --
    int cri;
    for(int t = 0; t < ycol; t++){//3 elements
        for(int j = 0; j < xcol; j++){//
            cri = 0;
            for(int k = j+1; k < xcol; k++){
                for(int i = 0; i < t; i++) if(list[j][i] != list[k][i]) cri = 1;
                if(cri == 1) break;
                if(list[j][t] > list[k][t]){
                    extemp = list[k];
                    list[k] = list[j];
                    list[j] = extemp;
// --- unique values --------------
        if(t == ycol-1){
            for(int j = 0; j < xcol-1; j++) unique += condition(list, j,ycol);//calling the condition function gives me error


As you could see that I'm calling the *condition* function inside the *unique_multiD* function. Is there anyway that I could get around with it?


7 Years
Discussion Span
Last Post by icez17

"calling the condition function gives me error" - what is the error? There should be no problem calling a function from another function.


The error message I got is:
"overloaded function with no contextual type information"
I'm using Dev C++. Does your compiler compile this code?

Edited by icez17: n/a


On line 57 'unique' is undefined.

If I define it, then I get:

In function ‘int unique_multiD(double**, int, int)’:

warning (really, error!): no return statement in function returning non-void

You are right. I didn't notice that! I spent the whole afternoon yesterday couldn't figure out how to make this code work.

After defining the variable unique, I could compile and run the code.
Thanks a lot.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.