wxiaoxiongw 2024-02-03 23:31 采纳率: 0%
浏览 7

c++文件分开编写时的链接错误

改了几个小时了,求解为什么老是一使用Manger函数就报链接错误

//这是文件method.cpp
#include "File.hpp"
/*错误    严重性    代码    说明    项目    文件    行    禁止显示状态LNK2005    "public: __cdecl Customer::Customer(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0Customer@@QEAA@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0@Z) 已经在 method.obj 中定义    Project1    D:\c++\Whale market\Project1\Project1\whalemarket.obj    1    */

string Customer::GetName() {
    return name;
}
string Customer::GetCipher() {
    return cipher;
}
string Customer::GetId() {
    return id;
}
void Customer::SetName(string name) {
    this->name = name;
}
void Customer::SetCipher(string cipher) {
    this->cipher = cipher;
}
Customer::Customer(string name, string cipher) {
    this->name = name;
    this->cipher = cipher;
}
Customer::Customer() {

}


void Product::show() {
    cout << "************************************************************************************" << endl;
    cout << "id" << "     " << "name" << "     " << "price" << "     " << "time" << "     " << "sellerId" << "     " << "status" << endl;
    cout << this->id << "     " << this->name << "     " << this->price << "     " << this->time << "     ";
    cout << this->seller.GetId() << "     " << status << endl;
    cout << "************************************************************************************" << endl;
}


string Manger::GetName() {
    return name;
}
string Manger::GetCipher() {
    return cipher;
}
string Manger::GetId() {
    return id;
}
void Manger::SetName(string name) {
    this->name = name;
}
void Manger::SetCipher(string cipher) {
    this->cipher = cipher;
}
Manger::Manger(string name, string cipher) {
    this->name = name;
    this->cipher = cipher;
}
Manger::Manger() {

}

void Manger::menu() {
    //cout << "================================================================================" << endl;
    //cout << "1:查看所有商品         2:搜索商品           3:查看所有订单     4:查看所有用户" << endl;
    //cout << "5:删除用户             6:下架商品           7:注销" << endl;
    //cout << "================================================================================" << endl;
    //cout << "请选择您的操作:";
    //char choice;
    //cin >> choice;
    //while (getchar());
    ///*switch((int)(choice - '0')){
    //case 1:
    //    AllProduct();
    //case 2:
    //    SearchProduct();
    //case 3:
    //    CheckAllGoods();
    //case 4:
    //    ShowAllCustomer();
    //case 5:
    //    DeletCustomer();
    //case 6:
    //    CancelProuct();
    //case 7:
    //    SignOut();
    //}*/
}
vector<Manger> mangers;
vector<Customer> customers;
vector<Product> pros;
void AllProduct() {
    for (Product a : pros) {
        a.show();
    }
}

void show() {
    
}
//这是File.hpp

#define _CRT_SECURE_NO_WARNINGS 0
#include<string>
#include<thread>
#include<iostream>
#include<vector>
using namespace std;

class Customer {
private:
    string name;
    string cipher;
    string id;

public:
    Customer();
    Customer(string name, string cipher);
    string GetId();
    string GetName();
    string GetCipher();
    void SetName(string name);
    void SetCipher(string cipher);
};



class Manger{
private:
    string name;
    string cipher;
    string id;

public:
    Manger();
    Manger(string name, string cipher);
    string GetId();
    string GetName();
    string GetCipher();
    void SetName(string name);
    void SetCipher(string cipher);
    
    void menu();
};


class Product {
public:
    void show();
private:
    string name;
    string status;
    string time;
    string id;
    Customer seller;
    double price;
};


void menu();
void AllProduct();
Product SearchProduct();
void CheckAllGoods();
void ShowAllCustomer();
void DeletCustomer();
void CancelProuct();
void SignOut();

  • 写回答

3条回答 默认 最新

  • threenewbee 2024-02-03 23:50
    关注
    评论

报告相同问题?

问题事件

  • 创建了问题 2月3日

悬赏问题

  • ¥20 公众号如何实现点击超链接后自动发送文字
  • ¥15 用php隐藏类名和增加类名
  • ¥15 算法设计与分析课程的提问
  • ¥20 汇川小型plc控制小米微电机
  • ¥15 用MATLAB汇总拟合图
  • ¥15 智能除草机器人方案设计
  • ¥15 对接wps协作接口实现消息发送
  • ¥15 SQLite 出现“Database is locked” 如何解决?
  • ¥15 已经加了学校的隶属邮箱了,为什么还是进不去github education?😭
  • ¥15 求会做聚类,TCN的朋友有偿线上指导。以下是目前遇到的问题