error: no matching function for call to...

I'm sure this is a case of not being able to see the obvious, but here goes. Keep in mind that I'm more than rusty with C/C++, so please treat me as a complete beginner.

I tried to separate out some templated functions, and g++ is now now giving me error messages like:

./src/nifti2normts.c++: In function ‘int transform_data(nifti_image*) [with SData = float, LData = double]’:
./src/nifti2normts.c++:275:50:   instantiated from here
./src/nifti2normts.c++:229:3: error: no matching function for call to ‘load_to_txyz(float*&, float*&, unsigned int&, unsigned int&, double&)’


The code is somewhat convoluted, but hopefully I've included the salient parts here.

UINT = unsigned int


The function I'm expecting to match is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
72: template<typename SData, typename LData>
73: int load_to_txyz(SData old_data, SData new_data, UINT timeseries_count, UINT timeseries_length) {
74:   UINT voxel_count = timeseries_count * timeseries_length;
75:   struct timeval t0;
76:   printf("Loading data into RAM in TXYZ format....\n");
77:   gettimeofday(&t0, NULL);
78:   UINT input_idx = 0;
79:   for(input_idx = 0; input_idx < voxel_count; ++ input_idx) {
80:     UINT idx_of_timeseries = input_idx % timeseries_count;
81:     UINT idx_in_timeseries = input_idx / timeseries_count;
82:     UINT new_idx = (idx_of_timeseries * timeseries_length) + idx_in_timeseries;
83:     new_data[new_idx] = old_data[input_idx];
84:   }
85:   printf("Loaded %d voxels into RAM in TXYZ format in %s seconds.\n",input_idx,bufSprintf("%0.6lf",tock(t0)));
86:   return 1;
87: }


The code at line 229 is (timeseries_count and timeseries_length are unsigned ints):

1
2
3
4
5
6
182: template<typename SData, typename LData> int transform_data(nifti_image * nifti_img) {
[...]
229:  if(! load_to_txyz<SData,LData>(old_data,new_data,timeseries_count,timeseries_length)) {
230:    printf("ERROR: Load file to TXZY failed!\n");
231:    return -1;
232:  }


At 275 it's:

1
2
3
274:  case DT_FLOAT:
275:    return transform_data<float,double>(nifti_img);
276    break;


Any ideas?

I can't post the whole code (too long), but hopefully the problem is in what I have posted.

Thanks!

**NOTE: Edited to reflect updated code RE: Zhuge's comment.
**NOTE: Added UINT definition, and types information for timeseries_count and timeseries_length)
Last edited on
Well, in your call you are passing five parameters, and the function itself only takes four.
Sorry. posting code snippets out-of-sync. I've removed the ,tmp:

1
2
3
4
5
6
182: template<typename SData, typename LData> int transform_data(nifti_image * nifti_img) {
[...]
229:  if(! load_to_txyz<SData,LData>(old_data,new_data,timeseries_count,timeseries_length)) {
230:    printf("ERROR: Load file to TXZY failed!\n");
231:    return -1;
232:  }


Same, identical error message. Still stumped.

Thanks!
Update the error, too, even if it's just that last parameter on the function being deleted. That said...old_data and new_data are float*, correct...?

I'd try to create a smaller, test program that works correctly except for the error you are getting. I tried
1
2
3
4
5
6
7
8
template <typename T, typename U>
int myfunc(T, T, unsigned int, unsigned int) {
	return 0;
}

int main() {
	myfunc<float*, float*>(0, 0, 0, 0);
}

which compiled fine, so it's probably the file structure or something else not in the snippets.
UPDATE: I've eliminated more or less everything from the code to leave just the templated function calls that give the errors.

@Zhuge - thanks for the help so far!

Here's what I have in src/test2.c++:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <stdlib.h>
#define UINT unsigned int
template<typename SData, typename LData> int bar(SData a, SData b, UINT c, UINT d) {
  return c * d;
}
template<typename SData, typename LData>
int foo(UINT z) {
  SData * a = (SData *)malloc(10);
  SData * b = (SData *)malloc(10);
  UINT c = 1;
  UINT d = 2;
  return bar<SData,LData>(a,b,c,d);
}
int main( int argc, const char** argv) {
  UINT z;
  return foo<float,double>(z);
}

Compiling with:
g++ -o ./test ./src/test2.c++

I get:
./src/test2.c++: In function ‘int foo(unsigned int) [with SData = float, LData = double]’:
./src/test2.c++:16:29:   instantiated from here
./src/test2.c++:12:34: error: no matching function for call to ‘bar(float*&, float*&, unsigned int&, unsigned int&)’

I clearly have no clue what's going on here.

Thanks!
Apparently, all I needed was to see the question I was asking! Oops! Could not see the signature differences through the c++ trees. The signature for bar() needed *a and *b, not a and b.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <stdlib.h>
#define UINT unsigned int
template<typename SData, typename LData> int bar(SData *a, SData *b, UINT c, UINT d) {
  return c * d;
}
template<typename SData, typename LData>
int foo(UINT z) {
  SData * a = (SData *)malloc(10);
  SData * b = (SData *)malloc(10);
  UINT c = 1;
  UINT d = 2;
  return bar<SData,LData>(a,b,c,d);
}
int main( int argc, const char** argv) {
  UINT z;
  return foo<float,double>(z);
}

Topic archived. No new replies allowed.