Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
separating class declaration (header file) and implementation (sourcefile)
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Giovanni Gherdovich, post: 3614720"] 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::operator()(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. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
separating class declaration (header file) and implementation (sourcefile)
Top