Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define unsafe(i) ( (i) >= 0 ? (i) : -(i) )
- [...]
- unsafe(x++); // x is incremented twice!
- unsafe(f()); // f() is called twice!
- [...]
- // header.hpp
- #include <iosfwd> // for std::ostream&
- #ifndef HEADER_HPP
- #define HEADER_HPP
- template <typename IteratorT>
- /*inline*/ void print_all(IteratorT begin, IteratorT end, std::ostream& out, char sep = ' ') {
- while (begin != end)
- out << *begin++ << sep;
- }
- #endif // !defined(HEADER_HPP)
- // test.cpp
- #include <iostream>
- #include <vector>
- #include "header.hpp"
- void test_function() {
- using namespace std;
- vector<int> vec;
- int x;
- while (cin >> x) vec.push_back(x);
- cout << "Results: ";
- print_all(vec.begin(), vec.end());
- cout << endl;
- }
- // main.cpp
- #include <iostream>
- #include <vector>
- #include "header.hpp"
- void test_function(); // Forward declaration.
- int main() {
- using namespace std;
- vector<int> xyz(23, 42);
- print_all(xyz);
- cout << endl << "Test call:" << endl;
- test_function();
- }
- $ g++ -Wall -pedantic main.cpp test.cpp
- CPoint
- {
- public:
- inline int x() const { return m_x ; }
- inline int y() const { return m_y ; }
- private:
- int m_x ;
- int m_y ;
- };
Add Comment
Please, Sign In to add comment