Plik Second.hpp:
#ifndef SECOND_HPP #define SECOND_HPP #include <iostream> using namespace std; namespace bbb { namespace { int b = 77; } class Klasa { public: void count2(); }; } #endif // SECOND_HPPPlik Second.cpp:
#include <vector> #include <boost/assign/list_of.hpp> #include "Second.hpp" namespace bbb { namespace { int value = 2; bool isEven(int i) { return (i == value); } } void Klasa::count2() { vector<int> v = boost::assign::list_of(1)(2)(3)(2)(1)(1); cout << "call bbb::Klasa::count2() = " << count_if(begin(v), end(v), isEven) << endl; } }Plik main.cpp:
#include <iostream> #include "Second.hpp" using namespace std; namespace std { void moja() { cout << "call std::moja()" << endl; } } namespace aaa { namespace { std::string a = "asdf"; void access() { cout << "call aaa::anonymous::access()" << endl; } } void show() { cout << "call aaa::show()" << endl; access(); } } int main() { std::moja(); aaa::access(); aaa::show(); bbb::Klasa s; s.count2(); // bool l = bbb::isEven(4); // ERROR! cout << "Access to member aaa::a = " << aaa::a << endl; cout << "Access to member bbb::b = " << bbb::b << endl; // cout << "Access to member bbb::value = " << bbb::value << endl; // ERROR! return 0; }Wyniki:
call std::moja() call aaa::anonymous::access() call aaa::show() call aaa::anonymous::access() call bbb::Klasa::count2() = 2 Access to member aaa::a = asdf Access to member bbb::b = 77
Brak komentarzy:
Prześlij komentarz