📄 multidimension.h
字号:
// MultiDimension.h: interface for the CMultiDimension class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_MULTIDIMENSION_H__7CD0AE20_ACF8_45FD_AB9A_40CD8A53AF53__INCLUDED_)
#define AFX_MULTIDIMENSION_H__7CD0AE20_ACF8_45FD_AB9A_40CD8A53AF53__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "afxtempl.h"
template<class Type, int nDim = 2>
class AFX_EXT_CLASS CMultiDimension
{
public:
int m_nDim ;
Type* m_pEle;
public:
CMultiDimension()
{
m_pEle = new Type[nDim];
m_nDim = nDim;
}
virtual ~CMultiDimension()
{
delete[] m_pEle;
}
Type& operator[](int n)
{
return m_pEle[n];
}
void SetAt(int n, Type val)
{
m_pEle[n] = val;
}
long operator *(CMultiDimension<Type, nDim>& md)
{
long tAdd = 0;
long tTmp = 0;
for(int i=0; i<nDim; i++) {
tTmp = m_pEle[i] - md.m_pEle[i];
tAdd += (tTmp * tTmp);
}
return tAdd;
}
CMultiDimension<Type, nDim> operator *(double fNum)
{
CMultiDimension<Type, nDim> md;
for(int i=0; i<nDim; i++) md.m_pEle[i] = m_pEle[i] * fNum;
return md;
}
CMultiDimension<Type, nDim> operator /(double fNum)
{
CMultiDimension<Type, nDim> md;
for(int i=0; i<nDim; i++) md.m_pEle[i] = m_pEle[i] / fNum;
return md;
}
CMultiDimension<Type, nDim> operator = (CMultiDimension<Type, nDim>& md)
{
for(int i=0; i<nDim; i++) m_pEle[i] = md.m_pEle[i];
return *this;
}
CMultiDimension<Type, nDim> operator + (CMultiDimension<Type, nDim>& md)
{
CMultiDimension<Type, nDim> tmd;
for(int i=0; i<nDim; i++) tmd.m_pEle[i] = m_pEle[i] + md.m_pEle[i];
return tmd;
}
CMultiDimension<Type, nDim> operator += (CMultiDimension<Type, nDim>& md)
{
*this = *this + md;
return *this;
}
CMultiDimension<Type, nDim> operator - (CMultiDimension<Type, nDim>& md)
{
CMultiDimension<Type, nDim> tmd;
for(int i=0; i<nDim; i++) tmd.m_pEle[i] = m_pEle[i] - md.m_pEle[i];
return tmd;
}
};
#endif // !defined(AFX_MULTIDIMENSION_H__7CD0AE20_ACF8_45FD_AB9A_40CD8A53AF53__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -