请教一个关于 实现Box类的问题 谢谢
超gogo 2009-04-12 01:36:34 做了一个箱子类,出现错误:
MSVCRTD.lib(crtexew.obj) : error LNK2019: 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainCRTStartup 中被引用
1>f:\Visual Studio 2008\Projects\q\Debug\q.exe : fatal error LNK1120: 1 个无法解析的外部命令
MSDN中说有可能是内置函数的问题,可是我只有标注的几个是内置函数,还有可能是没有定义函数体,可是我都定义了。
看了很久,不知道如何解决,请各位高手帮忙,谢谢!!!!!!
//Box.h
#pragma once
class CBox
{
public:
CBox(double l=1.0,double w=1.0,double h=1.0);
~CBox(void);
private:
double m_Length;
double m_Width;
double m_Height;
public:
double GetLength(void)const //inline
{
return m_Length;
}
double GetWidth(void) const //inline
{
return m_Width;
}
double GetHeight(void) const //inline
{
return m_Height;
}
double volume(void) const
{
return m_Length*m_Width*m_Height;
}
// 重载“+”
CBox operator +(const CBox& aBox) const;
// 重载“*”
CBox operator*(int n) const;
int operator/(const CBox& aBox) const;
};
///////////////////////////////////////////////////////////
//Box.cpp
#include "Box.h"
CBox::CBox(double l,double w,double h)
{
l= l<=0.0 ? 1.0:l;
w= w<=0.0 ? 1.0:w;
h= h<=0.0 ? 1.0:h;
m_Length= l>w ? l:w;
m_Width= w<l ? w:l;
m_Height=h;
}
CBox::~CBox(void)
{
}
// 重载“+”
CBox CBox::operator +(const CBox& aBox) const
{
return CBox(m_Length>aBox.m_Length ? m_Length:aBox.m_Length,
m_Width>aBox.m_Width ? m_Width:aBox.m_Width,
m_Height+aBox.m_Height);
}
// 重载“*” CBox * n 是CBox在前
CBox CBox::operator*(int n) const
{
if(n%2)
return CBox(m_Length,m_Width,m_Height*n);
else
return CBox(m_Length,m_Width*2.0,(n/2)*m_Height);
}
//重载“/”
int CBox::operator /(const CBox& aBox) const
{
int tc1=0;
int tc2=0;
tc1=static_cast<int>(m_Length/aBox.m_Length)*
static_cast<int>(m_Width/aBox.m_Width);
tc2=static_cast<int>(m_Length/aBox.m_Width)*
static_cast<int>(m_Width/aBox.m_Length);
return static_cast<int>((m_Height/aBox.m_Height)*
(tc1>tc2 ? tc1:tc2));
}
//////////////////////////////////////////////////////////////////
//BoxOperators.h
#pragma once
bool operator>(const double&value,const CBox & aBox);
bool operator<(const double &value,const CBox & aBox);
bool operator>(const CBox &aBox,const double &value);
bool operator<(const CBox &aBox,const double &value);
bool operator>=(const double &value,const CBox &aBox);
bool operator<=(const double &value,const CBox &aBox);
bool operator >=(const CBox& aBox,const double &value);
bool operator <=(const CBox& aBox,const double &value);
bool operator ==(const CBox& aBox,const double value);
bool operator ==(cosnt double value,const CBox& aBox);
CBox operator *(int n, CBox aBox);
double operator %(const CBox & aBox,const CBox & bBox);
/////////////////////////////////////////////////////////////
//BoxOperator.cpp
#include"Box.h"
////////////////////////////////////////////////////////
//重载'>' '<'
bool operator>(const double&value,const CBox & aBox)
{
return value>aBox.volume();}
bool operator<(const double &value,const CBox & aBox)
{
return value<aBox.volume();}
bool operator>(const CBox &aBox,const double &value)
{
return value<aBox; //上面已经重载定义了value < CBox,注意上面两种是double类型在前
}
bool operator<(const CBox &aBox,const double &value)
{
return value>aBox;}
//重载'>=''<='
bool operator>=(const double &value,const CBox &aBox)
{
return value>=aBox.volume();}
bool operator<=(const double &value,const CBox &aBox)
{
return value<=aBox.volume();}
bool operator >=(const CBox& aBox,const double &value)
{
return value<=aBox;
}
bool operator <=(const CBox& aBox,const double &value)
{
return value>=aBox;}
//重载'=='
bool operator ==(const CBox& aBox,const double value)
{
return aBox.volume()==value;}
bool operator ==(const double value,const CBox& aBox)
{
return aBox.volume()==value;}
CBox operator *(int n, CBox aBox)
{
return aBox*n; //aBox*n已经在Box.cpp中定义
}
double operator %(const CBox & aBox,const CBox & bBox)
{
return (aBox.volume()-(aBox/bBox)*bBox.volume());
}