[英]Unresolved External Symbol Error w/ Classes
#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;
}
This code gives me this error 这段代码给我这个错误
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
From what I can tell there isn't anything outright wrong, just looking for some fresh eyes to look at it. 据我所知,没有什么是完全错误的,只是寻找一些新鲜的眼睛来查看它。
I've been searching and have found no answer, Any help is appreciated. 我一直在搜索,但没有找到答案,我们将不胜感激。
Well, 好,
First change your class declaration to: 首先将您的类声明更改为:
Phone(); // remove Phone::
void setPhone(); // Phone::
Then setPhone
method: 然后是
setPhone
方法:
void Phone::setPhone() // add Phone:: and correct name to setPhone, not setphone
{
Phone phone;
cout << "Enter a country code: ";
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.