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

📄 vector.h

📁 斯坦福Energy211/CME211课《c++编程——地球科学科学家和工程师》的课件
💻 H
字号:
// Header file for Vector class#ifndef CLASS_VECTOR#define CLASS_VECTOR#include <ostream>	// Need this to declare <<class Vector {public:	// Constructs vector of given length and optional data	Vector( int length = 0, double *data = NULL )	{		m_length = length;		m_data = NULL;		allocate();		if ( data != NULL )			Set( data );	}	// Copy constructor	Vector( const Vector& v )	{		m_length = v.m_length;		m_data = NULL;		allocate();		Set( v.m_data );	}	// Creates 1-element vector from double (conversion)	Vector( double x )	{		m_length = 1;		m_data = NULL;		allocate();		Set( &x );	}	// Destructor	~Vector() 	{		deallocate();	}		// For obtaining length from outside code	inline int get_length() const { return m_length; }	// To add single element to vector	Vector operator,( double x ) const;	// To concatenate vectors	Vector operator,( const Vector& v ) const;	// This retrieves a single element, using Matlab-like	// syntax	double& operator()( int i ) const;	// This allows floating-point indices; value is obtained	// by linear interpolation between values at nearest	// integer indices	double operator()( double x ) const;	// This allows subvector extraction, using array of	// indices, as in Matlab	Vector operator()( int *indices, int length ) const;		// Copy-assignment operator	Vector& operator=( const Vector& v );	// Conversion from double, creates 1-element vector	Vector& operator=( double x );	// Element access	double& operator[]( int i ) const;		// To convert to array of double	operator double*() const { return m_data; }	private:	// Allocates space for elements	void allocate();	// Deallocates elements	void deallocate();	// Fills in values of element	void Set( double *data, int length = -1, int offset = 0 );	int m_length;	// length of vector	double *m_data;	// array of elements of vector} ;// Insertion (output) operatorstd::ostream& operator<<( std::ostream& out, const Vector& v );#endif

⌨️ 快捷键说明

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