I am trying to use templates along with vector in my code the following way:
In my header file:
template <typename V>
void changeConfig(char option, vector <V> & arg_in){
// ....
}
In the source file:
vector <int> p = {4};
changeConfig('w' ,p);
And this’s the error that I get:
/include/config.h: In member function ‘void Cfconfig::changeConfig(char, std::vector<_RealType>&) [with V = int]’:
src/config_test.cpp:10:38: instantiated from here
/include/config.h:68:25: error: no match for call to ‘(int_vector {aka std::vector}) (std::vector&)’
make: *** [featureconfig_test.o_dbg] Error 1
I tried the suggestions on this thread but none of them seem to work.
C++ Templates Error: no matching function for call
Any help would be appreciated. Thanks.
Okay, I made a short snippet of my code which gives the same error:
#include <iostream>
#include <stdio.h>
#include <stdarg.h>
#include <cstdio>
#include <opencv2/opencv.hpp>
#include <string.h>
#include <math.h>
#include <complex.h>
#include <dirent.h>
#include <fstream>
#include <typeinfo>
#include <unistd.h>
#include <stdlib.h>
#include <algorithm>
#include <array>
#include <initializer_list>
#include <vector>
#include <algorithm>
using namespace std;
template <typename V>
void changeConfig(char option, vector <V> & arg_in){
vector<int> window = {5};
vector<double> scale = {3};
switch(option){
case 'w':
window(arg_in);
break;
case 's':
scale(arg_in);
break;
}
}
int main(){
vector <int> p = {3};
changeConfig<int>('w', p);
return 0;
}
I compiled using :
g++ -std=c++0x test_template.cpp -o test
which gave me this error:
test_template.cpp: In function ‘void changeConfig(char, std::vector<_RealType>&) [with V = int]’:
test_template.cpp:45:33: instantiated from here
test_template.cpp:32:33: error: no match for call to ‘(std::vector) (std::vector&)’
test_template.cpp:35:33: error: no match for call to ‘(std::vector) (std::vector&)’
The problem is with
window(arg_in);andscale(arg_in);. You are trying to call anstd::vectorlike a function with anotherstd::vectoras an argument. I think you are trying to assign one vector to another, so just use assignment orswap.If you want to use
vector<double> scale, usescale.assign(arg_in.begin(), arg_in.end());instead or the other way aroundarg_in.assign(scale.begin(), scale.end());.