Function pointer with an object as parameter

I'm making a code that uses a Function pointer. The problem is, when I try to compile appears an error like:
error: no matching function for call to 'rnVector::rnVector()'

Here's part of the code:

1
2
3
phiFunction::phiFunction(double (*f)(rnVector), rnVector (*df)(rnVector)) {
	//... Here comes the code stuff...
}


I've read somewhere that there's a way of doing this work.
it seems that rnVector does not have default constructor.
MiiNiPaa, I know that. The problem is it shouldn't call the constructor.
It certainly seems like it would have to?
See. rnVector (*df)(rnVector) is a pointer to a function that receives a class as parameter. It certainly shouldn't call any constructor.
It have to call at least copy constructor. And if there is any variabledeclared as reVector x; It would call default one too
How can I call this copy constructor in the method signature???
You don't, as part of the way C++ works the copy constructor is called for you.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
struct PassMe
{
    PassMe() //default ctor
    {
        std::cout << "constructed" << std::endl;
    }
    PassMe(PassMe const &other) //copy constructor
    {
        std::cout << "copied" << std::endl;
    }
};

void f(PassMe pm)
{
}

void g(PassMe const &pm)
{
}

int main()
{
    PassMe please; //"constructed"
    f(please); //"copied"
    g(please); //nothing
}
Last edited on
1
2
3
4
phiFunction::phiFunction(double (*f)(rnVector), rnVector (*df)(rnVector)) {
	this->f = f;
	this->df = df;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class phiFunction {
private:

	rnVector x, d;
	double (*f)(rnVector);
	rnVector (*df)(rnVector);

public:

	/**
	 * Para construir um objeto phiFunction é necessário passar o ponteiro para uma função e sua derivada.
	 */
	phiFunction(double (*)(rnVector), rnVector (*)(rnVector));

	/**
	 * Estabelece as constantes para a função phi. (x,d).
	 */
	void setConst(rnVector, rnVector);

	/**
	 * Estabelece a função interna de phi(a)=f(x+a*d).
	 */
	void setFunc(double (*)(rnVector v), rnVector (*)(rnVector v));

	/**
	 * Retorna o valor da função phi no ponto a.
	 */
	double getFuncValue(double);

	/**
	 * Retorna o valor da derivada no ponto a.
	 */
	double getDiffValue(double);

	/**
	 * Retorna a dimensão dos vetores x e d.
	 */
	int getDim();
};


This is almost all the code. And the error is:
1
2
3
..\PhiFunction.cpp:3: error: no matching function for call to 'rnVector::rnVector()'
..\pnl.hpp:18: note: candidates are: rnVector::rnVector(int, double*)
..\pnl.hpp:9: note:                 rnVector::rnVector(const rnVector&)


I'm totaly confused why this doesn't work.
1
2
3
4
class phiFunction {
private:

	rnVector x, d;
These values are default constructed.
Sorry. Forgot part of the log.
1
2
3
4
5
6
7
8
g++ -O0 -g3 -Wall -c -fmessage-length=0 -o PhiFunction.o "..\\PhiFunction.cpp" 
..\PhiFunction.cpp: In constructor 'phiFunction::phiFunction(double (*)(rnVector), rnVector (*)(rnVector))':
..\PhiFunction.cpp:3: error: no matching function for call to 'rnVector::rnVector()'
..\pnl.hpp:18: note: candidates are: rnVector::rnVector(int, double*)
..\pnl.hpp:9: note:                 rnVector::rnVector(const rnVector&)
..\PhiFunction.cpp:3: error: no matching function for call to 'rnVector::rnVector()'
..\pnl.hpp:18: note: candidates are: rnVector::rnVector(int, double*)
..\pnl.hpp:9: note:                 rnVector::rnVector(const rnVector&)
Yes. There is two values, so default constructor gets called twice, and there is 2 errors
Oh, I understand now. Thank guys. I had already programmed in C and Java, and now I'm just jumped to C++. I didn't see that. Thanks.
Topic archived. No new replies allowed.