G
Giovanni Gherdovich
Hello,
As you will see from the following code snippets,
I'm trying to declare a function object in an header
file and implement it in a (different) source file, but my compiler
complains (he cannot find the implementation I provided,
apparently).
(the -c option tells the compiler to don't try to link,
just compile).
$ g++ -c addition.cpp
$ g++ -c program.cpp
program.cpp: In function `int main()':
program.cpp:5: error: no matching function for call to
`addition::addition(int, int)'
addition.h:2: note: candidates are: addition::addition()
addition.h:2: note: addition::addition(const
addition&)
here is the code:
// ------- this is the file addition.h
struct addition
{
int operator()(const int x, const int y) const;
};
// ------- end of the file addition.h
// ------- this is the file addition.cpp
#include "addition.h"
int addition:perator()(const int x, const int y) const
{
return x + y;
}
// ------- end of the file addition.cpp
// ------- this is the file program.cpp
#include "addition.h"
int main()
{
double a = addition(1,2);
}
// ------- end of the file program.cpp
Surely I'm missing something really obvious, but what?
Regards,
Giovanni Gh.
As you will see from the following code snippets,
I'm trying to declare a function object in an header
file and implement it in a (different) source file, but my compiler
complains (he cannot find the implementation I provided,
apparently).
(the -c option tells the compiler to don't try to link,
just compile).
$ g++ -c addition.cpp
$ g++ -c program.cpp
program.cpp: In function `int main()':
program.cpp:5: error: no matching function for call to
`addition::addition(int, int)'
addition.h:2: note: candidates are: addition::addition()
addition.h:2: note: addition::addition(const
addition&)
here is the code:
// ------- this is the file addition.h
struct addition
{
int operator()(const int x, const int y) const;
};
// ------- end of the file addition.h
// ------- this is the file addition.cpp
#include "addition.h"
int addition:perator()(const int x, const int y) const
{
return x + y;
}
// ------- end of the file addition.cpp
// ------- this is the file program.cpp
#include "addition.h"
int main()
{
double a = addition(1,2);
}
// ------- end of the file program.cpp
Surely I'm missing something really obvious, but what?
Regards,
Giovanni Gh.