Цитата(andrew_121 @ 28.5.2009, 08:00 ) | | Создать функцию не предлагать |
| Код | namespace stdext { template <typename T> class thread_safe_ { template<typename U> friend std::ostream& operator << (std::ostream&, const thread_safe_<U>&); template<typename U> friend thread_safe_<T> thread_safe(const T& v); thread_safe_(const T& v): value_(v) {} const T& value_; };
template <typename T> thread_safe_<T> thread_safe(const T& v) { return thread_safe_<T>(v); }
template <typename T> std::ostream& operator << (std::ostream& out, const thread_safe_<T>& v) { //тут синхронизируем //EnterCriticalSection... - out << v.value_ << std::flush; //LeaveCriticalSection... return out; } }
int main() { std::cout << stdext::thread_safe(5); return 0; }
|
так пойдет?
|