Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- class debug
- {
- private:
- class base_var
- {
- };
- public:
- template<typename T>
- class var : public base_var
- {
- public:
- var(const T& value)
- : m_value(value)
- {
- }
- inline var& operator=(const T& value)
- {
- if ((m_value = value) > m_th)
- std::cerr << "var raised above treshold (" << m_value << " > " << m_th << ")" << std::endl;
- }
- operator T() const
- {
- return m_value;
- }
- void notify_above(T treshold)
- {
- m_th = treshold;
- }
- private:
- T m_value;
- T m_th;
- };
- };
- int main(void)
- {
- debug::var<int> i = 0;
- i.notify_above(1000);
- for (int k = 0; k <= 1000; ++k)
- i = k;
- i = 1337;
- int unwatched_var = i;
- std::cout << "var = " << unwatched_var << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement