Advertisement
weberc2

C++ doesn't need a function specification in header

Sep 30th, 2012
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None | 0 0
  1.  
  2. --example.h--
  3. // empty file
  4.  
  5. --example.cpp--
  6. int add(int x, int y)
  7. {
  8.     return x + y;
  9. }
  10.  
  11. --main.cpp--
  12. #include <iostream>
  13. #include "example.h"
  14. int add(int x, int y); // forward declaration using function prototype
  15.  
  16. int main()
  17. {
  18.     using namespace std;
  19.     cout << "The sum of 3 and 4 is " << add(3, 4) << endl;
  20.     return 0;
  21. }
  22.  
  23. //works fine under g++
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement