请教一个关于 实现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());
}
...全文
67 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
超gogo 2009-04-12
  • 打赏
  • 举报
回复
原来我建的是WIN32程序,应该用WIN32控制台 不过仍然谢谢这位朋友 谢谢
冰霜icefrost 2009-04-12
  • 打赏
  • 举报
回复
你的程序配置错误了,
检查一下,配置中的 Linker -> System -> Subsystem 是不是设置成了Windows (/SUBSYSTEM:WINDOWS)
但你的程序是win32的,应该改为:Console (/SUBSYSTEM:CONSOLE)
超gogo 2009-04-12
  • 打赏
  • 举报
回复
我刚刚用书中带的源码也不行 也是出现这个错误,请问是不是我的VS2008有问题?????
cnzdgs 2009-04-12
  • 打赏
  • 举报
回复
extern "C" int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd)
{
……
}
超gogo 2009-04-12
  • 打赏
  • 举报
回复
你好 定义了main函数也不行,是WIN32程序
cnzdgs 2009-04-12
  • 打赏
  • 举报
回复
跟你上面贴的代码没关系,你的项目是什么类型?定义WinMain或main函数了吗?
超gogo 2009-04-12
  • 打赏
  • 举报
回复
很简单的原理 请各位朋友不要看到长就不看了 谢谢

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧