?? vector.h
字號(hào):
// 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
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -