d_store.h

来自「这是数据结构和算法的国外经典书籍.清华大学出版社出版的<数据结构C++语言」· C头文件 代码 · 共 49 行

H
49
字号
#ifndef STORE_CLASS
#define STORE_CLASS

#include <iostream>

using namespace std;

template <typename T>
class store
{
	public:
		store(const T& item = T());   	// constructor

		// access and update functions
		T getValue() const;              // return value
		void setValue(const T& item); 	// update value

		// overloaded operator << as a friend
		friend ostream& operator<< (ostream& ostr, const store<T>& obj)
		{
			ostr << "Value = " << obj.value;
			return ostr;
		}
	private:
		// data stored by the object
		T value;
};

// use an initialization list to assign value
template <typename T>
store<T>::store(const T& item): value(item)
{}

// return the current value
template <typename T>
T store<T>::getValue() const
{
	return value;
}

//   assign the argument as the new data member value
template <typename T>
void store<T>::setValue(const T& item)
{
	value = item;
}

#endif	// STORE_CLASS

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?