⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 d_store.h

📁 数据结构c++语言描述stl版 威廉兄弟的好书,值得看,这是配书代码
💻 H
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -