我刚刚写一个朋友圈管理系统,涉及两个类,Friend 类 和 Master类,因为涉及两个类的声明与实现,所以自然而然出现一个问题,就是 fatal error LNK1169: 找到一个或多个多重定义的符号,小白新手,不知如何解决,求各位赐教!(感谢)(还没写完的半成品)
Friend.h
#pragma once
using namespace std;
extern struct friends
{
char name[20]; //存储朋友姓名
char sex; //f or m
int age;
char phone[21];
char email[20];
char birthday[20];
int countEmail; //邮件记录
char textMessage[500]; //存储短信内容
int countPhone; //电话记录
char emailMessage[500];
};
struct friends pf[100];
class Friend
{
public:
friend class Master;
void save();
void deleteF(char namex[]);
private:
char name[20]; //存储朋友姓名
char sex; //f or m
int age;
char phone[21];
char email[20];
char birthday[20];
int countEmail; //邮件记录
char textMessage[500]; //存储短信内容
int countPhone; //电话记录
char emailMessage[500];
static int num;
};
friend.cpp
#define _CRT_SECURE_NO_WARNINGS
#include "friend.h"
#include <string.h>
int Friend::num = 0;
void Friend::save()
{
//将得到的朋朋友信息储存到结构体数组
strcpy(pf[num].name, this->name);
pf[num].sex = this->sex;
pf[num].age = age;
strcpy(pf[num].phone, this->phone);
strcpy(pf[num].email, this->email);
strcpy(pf[num].birthday, this->birthday);
pf[num].countEmail = this->countEmail;
strcpy(pf[num].textMessage, this->textMessage);
pf[num].countPhone = this->countPhone;
strcpy(pf[num].emailMessage, this->emailMessage);
++num;
}
void Friend::deleteF(char namex[])
{
int i = 0;
int flag = 0;
for (i = 0; i < num; ++i)
{
if (strcmp(pf[i].name, namex) == 0)
{
flag = i;
break;
}
}
//int j = 0;
for (i = flag + 1; i < num; ++i)
{
pf[i - 1] = pf[i];
}
--num;
}
Master.h
#pragma once
#include "friend.h"
using namespace std;
class Master
{
public:
void addFriend();
void deleteFriend();
void modifyFriend();
void displayFriend();
private:
Friend fri;
};
Master.cpp
#include "Master.h"
#include <iostream>
#include <string>
using namespace std;
void Master::addFriend()
{
cout << "请输入新增朋友的姓名: ";
cin >> fri.name;
cout << "请输入新增朋友的性别(f or m): ";
cin >> fri.sex;
cout << "请输入新增朋友的年龄: ";
cin >> fri.age;
cout << "请输入新增朋友的电话号码: ";
cin >> fri.phone;
cout << "请输入新增朋友的邮箱地址: ";
cin >> fri.email;
cout << "请输入新增朋友的生日: ";
cin >> fri.birthday;
cout << "请输入新增朋友的出邮记录: ";
cin >> fri.countEmail;
cout << "请输入新增朋友的储存短信内容: ";
cin >> fri.textMessage;
cout << "请输入新增朋友的电话记录: ";
cin >> fri.countPhone;
cout << "请输入新增朋友的邮件消息: ";
cin >> fri.emailMessage;
fri.save();
//++num;
}
void Master::deleteFriend()
{
char namex[20];
cout << "请输入您要输出朋友的姓名: ";
cin >> namex;
fri.deleteF(namex);
}
void Master::modifyFriend()
{
}
void Master::displayFriend()
{
}
main.cpp
#include <iostream>
#include "Master.h"
int main()
{
Master mas;
mas.addFriend();
return 0;
}