Closed. This question needs to be more focused。它当前不接受答案。
想改善这个问题吗?更新问题,使其仅通过editing this post专注于一个问题。
4年前关闭。
不断收到错误
致命错误LNK1120:2个未解决的外部零件
无效CMSCalculatorDlg :: OnBnClickedBtn4()
{
想改善这个问题吗?更新问题,使其仅通过editing this post专注于一个问题。
4年前关闭。
不断收到错误
error LNK2001: unresolved external symbol "public: void __thiscall CMSCalculatorDlg::OnEnChangeEdtDisplay(void)" (?OnEnChangeEdtDisplay@CMSCalculatorDlg@@QAEXXZ)
error LNK2001: unresolved external symbol "public: void __thiscall CMSCalculatorDlg::OnBnClickedChkInverse(void)" (?OnBnClickedChkInverse@CMSCalculatorDlg@@QAEXXZ)
致命错误LNK1120:2个未解决的外部零件
#include "stdafx.h"
#include "MSCalculator.h"
#include "MSCalculatorDlg.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
CMSCalculatorDlg::CMSCalculatorDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMSCalculatorDlg::IDD, pParent)
, m_display(_T(""))
, m_input(0)
, m_output(0)
, m_operator(0)
, m_invert(FALSE)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMSCalculatorDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDT_Display, m_display);
DDX_Check(pDX, IDC_CHK_Inverse, m_invert);
}
BEGIN_MESSAGE_MAP(CMSCalculatorDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BTN_Cancel, &CMSCalculatorDlg::OnBnClickedBtnCancel)
ON_BN_CLICKED(IDC_BTN_1, &CMSCalculatorDlg::OnBnClickedBtn1)
ON_BN_CLICKED(IDC_BTN_ADD, &CMSCalculatorDlg::OnBnClickedBtnAdd)
ON_BN_CLICKED(IDC_BTN_EQUAL, &CMSCalculatorDlg::OnBnClickedBtnEqual)
ON_BN_CLICKED(IDC_BTN_MINUS, &CMSCalculatorDlg::OnBnClickedBtnMinus)
ON_BN_CLICKED(IDC_BTN_LN, &CMSCalculatorDlg::OnBnClickedBtnLn)
ON_BN_CLICKED(IDC_CHK_Inverse, &CMSCalculatorDlg::OnBnClickedChkInverse)
ON_BN_CLICKED(IDC_BTN_2, &CMSCalculatorDlg::OnBnClickedBtn2)
ON_BN_CLICKED(IDC_BTN_3, &CMSCalculatorDlg::OnBnClickedBtn3)
ON_BN_CLICKED(IDC_BTN_4, &CMSCalculatorDlg::OnBnClickedBtn4)
ON_BN_CLICKED(IDC_BTN_5, &CMSCalculatorDlg::OnBnClickedBtn5)
ON_BN_CLICKED(IDC_BTN_6, &CMSCalculatorDlg::OnBnClickedBtn6)
ON_BN_CLICKED(IDC_BTN_7, &CMSCalculatorDlg::OnBnClickedBtn7)
ON_BN_CLICKED(IDC_BTN_8, &CMSCalculatorDlg::OnBnClickedBtn8)
ON_BN_CLICKED(IDC_BTN_9, &CMSCalculatorDlg::OnBnClickedBtn9)
ON_EN_CHANGE(IDC_EDT_Display, &CMSCalculatorDlg::OnEnChangeEdtDisplay)
ON_BN_CLICKED(IDC_BTN_0, &CMSCalculatorDlg::OnBnClickedBtn0)
ON_BN_CLICKED(IDC_BTN_SQUARED, &CMSCalculatorDlg::OnBnClickedBtnSquared)
ON_BN_CLICKED(IDC_BTN_MULTIPLY, &CMSCalculatorDlg::OnBnClickedBtnMultiply)
ON_BN_CLICKED(IDC_BTN_DIVIDE, &CMSCalculatorDlg::OnBnClickedBtnDivide)
ON_BN_CLICKED(IDC_BTN_POWER, &CMSCalculatorDlg::OnBnClickedBtnPower)
ON_BN_CLICKED(IDC_BTN_LOG, &CMSCalculatorDlg::OnBnClickedBtnLog)
ON_BN_CLICKED(IDC_BTN_SINE, &CMSCalculatorDlg::OnBnClickedBtnSine)
ON_BN_CLICKED(IDC_BTN_COSINE, &CMSCalculatorDlg::OnBnClickedBtnCosine)
ON_BN_CLICKED(IDC_BTN_CUBED, &CMSCalculatorDlg::OnBnClickedBtnCubed)
ON_BN_CLICKED(IDC_BTN_TANGENT, &CMSCalculatorDlg::OnBnClickedBtnTangent)
ON_BN_CLICKED(IDC_BTN_SINEH, &CMSCalculatorDlg::OnBnClickedBtnSineh)
ON_BN_CLICKED(IDC_BTN_COSINEH, &CMSCalculatorDlg::OnBnClickedBtnCosineh)
ON_BN_CLICKED(IDC_BTN_TANGENTH, &CMSCalculatorDlg::OnBnClickedBtnTangenth)
ON_BN_CLICKED(IDC_BTN_FACTORIAL, &CMSCalculatorDlg::OnBnClickedBtnFactorial)
ON_BN_CLICKED(IDC_BTN_INVFUC, &CMSCalculatorDlg::OnBnClickedBtnInvfuc)
END_MESSAGE_MAP()
BOOL CMSCalculatorDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CMSCalculatorDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
void CMSCalculatorDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
HCURSOR CMSCalculatorDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CMSCalculatorDlg::OnBnClickedBtnCancel()
{
m_display = _T("");
UpdateData(false);
}
void CMSCalculatorDlg::OnBnClickedBtnAdd()
{
UpdateData(true);
m_input = _tstof(m_display);
m_output = m_input;
m_display = _T("");
m_operator = 0;
UpdateData(false);
}
void CMSCalculatorDlg::OnBnClickedBtnMinus()
{
UpdateData(true);
m_input = _tstof(m_display);
m_output = m_input;
m_display = _T("");
m_operator = 1;
}
void CMSCalculatorDlg::OnBnClickedBtnMultiply()
{
UpdateData(true);
m_input = _tstof(m_display);
m_output = m_input;
m_display = _T("");
m_operator = 2;
}
void CMSCalculatorDlg::OnBnClickedBtnDivide()
{
UpdateData(true);
m_input = _tstof(m_display);
m_output = m_input;
m_display = _T("");
m_operator = 3;
}
void CMSCalculatorDlg::OnBnClickedBtnEqual()
{
UpdateData(true);
m_input = _tstof(m_display);
switch(m_operator)
{
case 0:
m_output += m_input;
break;
case 1:
m_output -= m_input;
break;
case 2:
m_output *= m_input;
break;
case 3:
m_output /= m_input;
break;
}
m_display.Format(_T("%.4f"), m_output); // convert from double to C-string
UpdateData(false);
}
void CMSCalculatorDlg::OnBnClickedBtnLn()
{
UpdateData(true);
m_input = _tstof(m_display);
if(m_invert == false)
m_output = log(m_input);
else
m_output = exp(m_input);
m_display.Format(_T("%.4f"), m_output); // converter
UpdateData(false);
m_display =_T("");
}
void CMSCalculatorDlg::OnBnClickedBtnLog()
{
UpdateData(true);
m_input = _tstof(m_display);
if(m_invert == false)
m_output = log10(m_input);
else
m_output = pow(10,m_input);
m_display.Format(_T("%.4f"), m_output); // converter
UpdateData(false);
m_display =_T("");
}
void CMSCalculatorDlg::OnBnClickedBtn0()
{
m_display += _T("0");
UpdateData(false);
}
void CMSCalculatorDlg::OnBnClickedBtn1()
{
m_display += _T("1");
UpdateData(false);
}
void CMSCalculatorDlg::OnBnClickedBtn2()
{
m_display += _T("2");
UpdateData(false);
}
void CMSCalculatorDlg::OnBnClickedBtn3()
{
m_display += _T("3");
UpdateData(false);
}
无效CMSCalculatorDlg :: OnBnClickedBtn4()
{
m_display += _T("4");
UpdateData(false);
}
void CMSCalculatorDlg::OnBnClickedBtn5()
{
m_display += _T("5");
UpdateData(false);
}
void CMSCalculatorDlg::OnBnClickedBtn6()
{
m_display += _T("6");
UpdateData(false);
}
void CMSCalculatorDlg::OnBnClickedBtn7()
{
m_display += _T("7");
UpdateData(false);
}
void CMSCalculatorDlg::OnBnClickedBtn8()
{
m_display += _T("8");
UpdateData(false);
}
void CMSCalculatorDlg::OnBnClickedBtn9()
{
m_display += _T("9");
UpdateData(false);
}
void CMSCalculatorDlg::OnBnClickedBtnSquared()
{
UpdateData(true);
m_input = _tstof(m_display);
if(m_invert == false)
m_output = pow(m_input,2.0);
else
m_output = pow(m_input,0.5);
m_display.Format(_T("%.4f"), m_output); // converter
UpdateData(false);
m_display =_T("");
}
void CMSCalculatorDlg::OnBnClickedBtnCubed()
{
UpdateData(true);
m_input = _tstof(m_display);
if(m_invert == false)
m_output = pow(m_input,3.0);
else
m_output = pow(m_input,1/3);
m_display.Format(_T("%.4f"), m_output); // converter
UpdateData(false);
m_display =_T("");
}
void CMSCalculatorDlg::OnBnClickedBtnPower()
{
UpdateData(true);
m_input = _tstof(m_display);
if(m_invert == false)
m_output = pow(m_input,m_input);
else
m_output = pow(m_input,m_input);
m_display.Format(_T("%.4f"), m_output); // converter
UpdateData(false);
m_display =_T("");
}
void CMSCalculatorDlg::OnBnClickedBtnSine()
{
UpdateData(true);
m_input = _tstof(m_display);
if(m_invert == false)
m_output = sin(m_input);
else
m_output = asin(m_input);
m_display.Format(_T("%.4f"), m_output); // converter
UpdateData(false);
m_display =_T("");
}
void CMSCalculatorDlg::OnBnClickedBtnCosine()
{
UpdateData(true);
m_input = _tstof(m_display);
if(m_invert == false)
m_output = cos(m_input);
else
m_output = acos(m_input);
m_display.Format(_T("%.4f"), m_output); // converter
UpdateData(false);
m_display =_T("");
}
void CMSCalculatorDlg::OnBnClickedBtnTangent()
{
UpdateData(true);
m_input = _tstof(m_display);
if(m_invert == false)
m_output = tan(m_input);
else
m_output = atan(m_input);
m_display.Format(_T("%.4f"), m_output); // converter
UpdateData(false);
m_display =_T("");
}
void CMSCalculatorDlg::OnBnClickedBtnSineh()
{
UpdateData(true);
m_input = _tstof(m_display);
if(m_invert == false)
m_output = sinh(m_input);
else
m_output = log(m_input + sqrt(m_input * m_input + 1));
m_display.Format(_T("%.4f"), m_output); // converter
UpdateData(false);
m_display =_T("");
}
void CMSCalculatorDlg::OnBnClickedBtnCosineh()
{
UpdateData(true);
m_input = _tstof(m_display);
if(m_invert == false)
m_output = cosh(m_input);
else
m_output = log(m_input + sqrt(m_input * m_input - 1));
m_display.Format(_T("%.4f"), m_output); // converter
UpdateData(false);
m_display =_T("");
}
void CMSCalculatorDlg::OnBnClickedBtnTangenth()
{
UpdateData(true);
m_input = _tstof(m_display);
if(m_invert == false)
m_output = tanh(m_input);
else
m_output = 0.5*log(1+m_input/1-m_input);
m_display.Format(_T("%.4f"), m_output); // converter
UpdateData(false);
m_display =_T("");
}
void CMSCalculatorDlg::OnBnClickedBtnFactorial()
{
UpdateData(true);
m_input = _tstof(m_display);
for(int i=1; i <= m_input;i++)
{
m_output = m_output*i;
}
m_display.Format(_T("%.4f"), m_output); // converter
UpdateData(false);
m_display =_T("");
}
void CMSCalculatorDlg::OnBnClickedBtnInvfuc()
{
UpdateData(true);
m_input = _tstof(m_display);
m_output = 1/m_input;
m_display.Format(_T("%.4f"), m_output); // converter
UpdateData(false);
m_display =_T("");
}
最佳答案
您尚未提供CMSCalculatorDlg::OnEnChangeEdtDisplay
和CMSCalculatorDlg::OnBnClickedChkInverse
的定义。
您已经声明了这些方法,但未定义它们。添加缺少的定义后,链接器将很高兴。
09-06 16:25