在VC++中编译项目时出现问题。当我编译项目时,它会给出两个错误,一个是针对重载成员的,另一个是针对end-of-file
的。尽管我在所有类(class)的末尾都使用了分号,但仍会出现此错误。
这是CGCustomert.cpp
:
#include "stdafx.h"
#include "GCustomert.h"
#include<string>
using namespace std;
CGCustomert::CGCustomert(void)
{
m_strName = _T("Unknown");
m_bMale = TRUE;
m_strPhoneNo = _T("88888888888");
m_strQQNo = _T("00000");
m_strNumber =_T("");
m_strDate =_T("");
m_strCompanyName = _T("");
m_strAddress = _T("");
m_iAge = 0;
m_strState = _T("");
m_strLimit = _T("");
m_strRemarks =_T("");
};
CGCustomert::CGCustomert(CString strName, BOOL bMale, CString strPhoneNo, CString strQQNo, int iAge,CString strNumber,
CString strDate,CString strCompanyName,CString strAddress,CString strState,CString strLimit,CString strRemarks )
: m_strName(strName), m_bMale(bMale), m_strPhoneNo(strPhoneNo), m_strQQNo(strQQNo), m_strNumber ( strNumber),m_strDate ( strDate),
m_strCompanyName ( strCompanyName),m_strAddress ( strAddress),m_iAge ( iAge), m_strState ( strState),m_strLimit (strLimit),
m_strRemarks ( strRemarks)
{
}; //end of CPerson::CPerson()
CGCustomert::~CGCustomert(void)
{
};
该错误将我定向到
CGCustomert
类的定义: #pragma once
class CGCustomert
{
public:
CGCustomert(void);
CGCustomert(CString strName, BOOL bMale = TRUE, CString strPhoneNo = _T("88888888888"),
CString strQQNo = _T("0000"), CString strNumber =_T(""),CString strDate =_T(""),
CString strCompanyName = _T(""),CString strAddress = _T(""),int iAge = 0,CString strState = _T(""),CString
strLimit = _T(""),CString strRemarks =_T(""));
~CGCustomert(void);
public:
CString GetName() { return m_strName; }
BOOL IsMale() { return m_bMale; }
CString GetPhoneNo() { return m_strPhoneNo; }
CString GetQQNo() { return m_strQQNo; }
CString GetNumber() { return m_strNumber; }
CString GetDate() {return m_strDate; }
CString GetCompanyName() {return m_strCompanyName;}
CString GetAddress() {return m_strAddress;}
int GetAge() {return m_iAge; }
CString GetState() {return m_strState;}
CString GetLimit() {return m_strLimit;}
CString GetRemarks() {return m_strRemarks; }
void SetName(CString strName) { m_strName = strName; }
void SetMale(BOOL bMale) { m_bMale = bMale; }
void SetPhoneNo(CString strPhoneNo) { m_strPhoneNo = strPhoneNo; }
void SetQQNo(CString strQQNo) { m_strQQNo = strQQNo; }
void SetNumber(CString strNumber) { m_strNumber = strNumber; }
void SetDate(CString strDate) { m_strDate = strDate; }
void SetCompanyName(CString strCompanyName) { m_strCompanyName = strCompanyName;}
void SetAddress(CString strAddress) {m_strAddress = strAddress;}
void SetAge(int iAge) { m_iAge = iAge;}
void SetState(CString strState) { m_strState = strState;}
void SetLimit(CString strLimit) { m_strLimit = strLimit;}
void SetRemarks(CString strRemarks ) {m_strRemarks = strRemarks;}
public:
CString m_strName;
BOOL m_bMale;
CString m_strPhoneNo;
CString m_strQQNo;
CString m_strNumber;
CString m_strDate;
CString m_strCompanyName;
CString m_strAddress;
int m_iAge;
CString m_strState;
CString m_strLimit;
CString m_strRemarks;
};
错误发生在以
: m_strName(strName)
开头的行。我已经阅读了其他类似的答案来解决此问题,但是它们对于这些问题而言过于具体,因此我无法在我的案例中使用它。有人可以让我知道如何解决此问题吗?
最佳答案
非默认构造函数的定义中的参数顺序与声明中的参数顺序不同。正确的顺序是:
CGCustomert::CGCustomert(CString strName, BOOL bMale, CString strPhoneNo,
CString strQQNo, CString strNumber, CString strDate,
CString strCompanyName, CString strAddress, int iAge, CString strState, CString
strLimit, CString strRemarks) :
m_strName(strName), m_bMale(bMale), m_strPhoneNo(strPhoneNo), m_strQQNo(strQQNo), m_strNumber(strNumber), m_strDate(strDate),
m_strCompanyName(strCompanyName), m_strAddress(strAddress), m_iAge(iAge), m_strState(strState), m_strLimit(strLimit),
m_strRemarks(strRemarks)
{}