#include <iostream>
#include <string>
using namespace std;
class Phone
{
public:
int countryCode, areaCode, mainNum;
string type;
Phone::Phone();
void Phone::setPhone();
void getPhone();
};
Phone::Phone()
{
countryCode = 0;
areaCode = 0;
mainNum = 0;
type = "HOME";
}
void setphone()
{
Phone phone;
cout << "Enter a country code: ";
cin >> phone.countryCode;
cout << "Enter an area code: ";
cin >> phone.areaCode;
cout << "Enter a number: ";
cin >> phone.mainNum;
cout << "Enter a type (HOME, OFFICE, FAX, CELL, or PAGER): ";
cin >> phone.type;
}
int main()
{
Phone p;
Phone();
p.setPhone();
cout << p.countryCode << "-" << p.areaCode << "-" << p.mainNum << " " << p.type << endl;
}
此代码给了我这个错误
Error 1 error LNK2019: unresolved external symbol "public: void __thiscall Phone::setPhone(void)" (?setPhone@Phone@@QAEXXZ) referenced in function _main c:\Users\Adam\documents\visual studio 2013\Projects\ConsoleApplication22\ConsoleApplication22\Source.obj ConsoleApplication22
Error 2 error LNK1120: 1 unresolved externals c:\users\adam\documents\visual studio 2013\Projects\ConsoleApplication22\Debug\ConsoleApplication22.exe 1 1 ConsoleApplication22
据我所知,没有什么是完全错误的,只是寻找一些新鲜的眼睛来看待它。
我一直在寻找并且没有找到答案,感谢任何帮助。
答案 0 :(得分:0)
好吧,
首先将您的班级声明更改为:
Phone(); // remove Phone::
void setPhone(); // Phone::
然后setPhone
方法:
void Phone::setPhone() // add Phone:: and correct name to setPhone, not setphone
{
Phone phone;
cout << "Enter a country code: ";
...