Constructor Error

I am getting a syntax error in my program while calling a parameterised constructor. The error is: no instance of constructor matches the argument list.

I understand the error but I don't know why I am getting it since I am passing the correct parameters.

Declaration of Constructor in header file CFilterEngine.h:

CFilterEngine( std::vector<double> m_impluseResponse, int *numtaps, int *numband, std::vector<double> bands, std::vector<double> des, std::vector<double> weight, int *type, int *griddensity, int *iblockSize );

Calling of constructor in main code (test.cpp):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  int iTaps = 75;
  std::vector<double> impluseResponse;
  impluseResponse.resize(iTaps, 0);
  int iBands;
  double dBands[] = { 0, 0.2, 0.4, 0.5 };
  double dDes[] = { 1, 1, 0, 0 };
  double dWeights[] = { 1, 1 };
  int iType = 1;
  int iGridDensity = 20;
  int iblockSize;
  std::cout << "Input the block size : ";
  std::cin >> iblockSize;

CFilterEngine engine(impluseResponse, iTaps, iBands, &(dBands[0]),&(dDes[0]), &(dWeights[0]), iType, iGridDensity, iblockSize);  



My goal is that I want to create a vector in test.cpp function and it will be populated in the constructor of CFilterEngine. Can anyone tell me what I am doing wrong?
Last edited on
Second parameter should be an int*. You're passing an int.
Third parameter should be an int*. You're passing an int.
Fourth parameter should be a std::vector<double>. You're passing a double*.
Likewise fifth, likewise sixth, and all the rest. You got only the first parameter right.

I am passing the correct parameters.

Not even close.
Last edited on
I thought when I pass a variable then the constructor will decide based on if it expects int or int* to pass either the value or the pointer automatically. Anyways that was my misunderstanding.

But even when I pass pointers for int I get the same error.
 
CFilterEngine engine(impluseResponse, &iTaps, &iBands, &(dBands[0]), &(dDes[0]), &(dWeights[0]), &iType, &iGridDensity, &iblockSize);


For 4th, 5th and 6th parameters I have declared arrays and constructor expects vector so I am passing as above. I have done same thing in another part of code and there it works fine.

Declaration
 
remez(double h[], int *numtaps, int *numband, const double bands[], const double des[], const double weight[], int *type, int *griddensity)


And calling function

RemezFilterDesign::remez(&(m_impluseResponse[0]), numtaps, numband, &(bands[0]), &(des[0]), &(weight[0]), type, griddensity);

Here m_impluseResponse, bands, des and weights are all vectors but function expects arrays but here I get no error. so why for the constructor?
Last edited on
For 4th, 5th and 6th parameters I have declared arrays and constructor expects vector so I am passing as above.


An array is not the same thing as a vector. If it expects a vector, you have to pass a vector.




 
RemezFilterDesign::remez(&(m_impluseResponse[0]), numtaps, numband, &(bands[0]), &(des[0]), &(weight[0]), type, griddensity);


bands is a vector (of int? I assume a vector<int>). bands[0] is the first element. &(bands[0]) is a pointer to the first element. You are NOT passing a vector. You are passing a int*.

In C++, when you pass an array, you're really passing a pointer to the first element. So that's why it works in this case; because the function expects a pointer, and you're passing a pointer. To summarise:

 
RemezFilterDesign::remez(&(m_impluseResponse[0]), numtaps, numband, &(bands[0]), &(des[0]), &(weight[0]), type, griddensity);

Here, you are NOT passing any vectors. The function expects a pointer, and you are passing it a pointer to the first element in the array. You're not passing a vector. You're passing a pointer.

Here m_m_impluseResponse, bands, des and weights are all vectors but function expects arrays but here I get no error. so why for the constructor?

Again, to make it really clear, you are NOT passing vectors here. The function expects pointers (arrays), you're passing pointers, all happy.


In the constructor call, it expects vectors and you're passing pointers, so it fails.



Last edited on
Ok. I understood the problem. but i still don't know how to pass a vector by reference. Anyways thanks for explaining what the error is.
but i still don't know how to pass a vector by reference


Exactly the same way as passing by value. The receiving function knows it uses a reference.

1
2
3
4
5
6
7
8
void someFunction(vector<int>& param_by_reference)
{
  ...
}


vector<int> aVector;
someFunction(aVector); // aVector is passed by reference because that's what the receiving function takes 
Topic archived. No new replies allowed.