未知功能已经存在错误
unknown function already exists error
我编译代码时会出现一个奇怪的错误,它说成员函数AlReadys存在于另一个类中,该类别没有错误说
错误lnk2005" public:void __thiscall会员type :: print(void)" (?print@membershipType @@ qaexxz)已经定义 pershytype.obj project1 c: users okpal source repos project1 project1 project1 source.obj
以及
错误lnk1169一个或多个倍数定义的符号 找到Project1 C: User Okpal source repos project1 debug project1.exe 1
我想知道是否有人可以帮助找出错误我的班级代码在下面
#include <iostream>
#include <string>
using namespace std;
class addressType { //class defintions and prototypes member variables
public:
addressType();
string streetAddressNum, streetName, streetType, city, stateInitials;
int zipCode;
};
class personType
{
public:
personType();
string firstName;
string lastName;
int personNum;
char gender;
int personID;
addressType address;
void setInterest1(string interest1);//mutator
void setInterest2(string interest2);
void printPerson();
string GetInterest1() const; // Accessor
string GetInterest2() const;
private:
string SetInterest1;
string SetInterest2;
};
//define membershipType class
class membershipType :public personType
{
public:
char membership_type;
char membership_status;
membershipType(); // 1st constructor
membershipType(char, char); // 2nd constructor
void print();
};
void membershipType::print()
{
cout << GetInterest1();
}
pershertype的源代码
#include "personType.h"
personType::personType()
{
int personNum = 0;
int personID = 0;
}
addressType::addressType() {
int zipCode = 0;
}
void personType::setInterest1(string interest1) {
SetInterest1 = interest1;
}//mutator
void personType::setInterest2(string interest2) {
SetInterest2 = interest2;
}
string personType:: GetInterest1() const
{
return SetInterest1;
}// Accessor
string personType:: GetInterest2() const {
return SetInterest2;
}
void personType :: printPerson() {//constructor
cout << firstName << " " << lastName << " " << gender << " " <<
personID << " " << address.streetAddressNum << " "
<< address.streetName << " " << address.streetType
<< " " << address.city << " " << address.stateInitials
<< " " << address.zipCode << " " << SetInterest1 << " " << SetInterest2 << endl;
}
您在第一个代码块中具有membershipType::print()
的定义,我认为我可以从标题文件复制。在C 中,将标题文件的内容插入到包含它们的每个文件中。据推测,您的程序中至少有两个源文件,其中包括此标头。当这些源文件被编译到对象文件时,两者都将包含membershipType::print()
的定义。当您尝试链接它们时,链接器将检测到两个文件都包含相同符号的定义。它不知道该在哪里使用,因此返回错误。
解决此问题的最简单方法是将membershipType::print()
的定义移至源文件。您也可以通过内联。
相关文章:
- 我正在尝试制作一个自平衡机器人,但编译时存在错误。我不知道如何解决它
- Visual Studio 2019在内置库中存在错误
- 以下 OpenCV 源代码中是否存在错误?(#ifdef 没有 #else)
- 在存在错误代码的情况下输出参数与 NRVO
- 为什么我的删除功能中存在错误
- 哪个编译器(如果有的话)在参数包扩展中存在错误
- 未知功能已经存在错误
- progam在std :: getline AM之后停止响应,代码中是否存在错误
- Netuseradd用户已经存在错误
- GCC 4.4.1是否存在错误,因为它不接受ctor初始值设定项中的注入类名
- Visual C++中的外部模板是否存在错误
- 类模板成员不存在错误
- 如果构造函数中存在错误,请停止进程
- purify中存在错误的内存泄漏
- C++中是否存在错误类型
- 来自 vtable 的未定义符号是否意味着接口和实现之间存在错误
- 为什么我遇到此代码的分段错误?此代码几乎没有运行,因此构造函数或复制构造函数中可能存在错误
- c ++ 11 参数包在 Apple LLVM 7.0.0 中存在错误行为,但适用于 GCC-5.1
- 文件输出中存在错误字符
- 在boost::mutex构造函数中同时写入同一内存区域可能存在错误