//client.h
#pragma once
#ifndef _CLINET
#define _CLIENT
#include <iostream>
#include <string>
using namespace std;
class CLIENT {
public:
static int serveNum;//静态数据成员:服务器数
static void changeServeName(string s);//静态成员函数:改变服务器名称
CLIENT();//默认构造函数
CLIENT(string name);//构造函数
~CLIENT();
void showName();//显示服务器名称
static void showNum();//显示服务器数量
private:
static string serveName;//静态数据成员:服务器名称
};
#endif
//client1.cpp
#pragma once
#include "client.h"
CLIENT::CLIENT() {
serveName = "name1";
cout << "创建一台服务器" << endl;
serveNum++;
}
CLIENT::CLIENT(string name) {
serveName = name;
cout << "创建一台服务器" << endl;
serveNum++;
}
CLIENT::~CLIENT() {}
int CLIENT::serveNum = 0;
string CLIENT::serveName = "NULL";
void CLIENT::showName() {
cout << serveName << endl;
}
void CLIENT::showNum() {
cout <<"当前共有服务器数为:"<< serveNum << endl;
}
void CLIENT::changeServeName(string s) {
serveName = s;
}
//main.cpp
#include "client1.cpp"
using namespace std;
int main() {
string s;
CLIENT c1;
CLIENT c2("name2");
CLIENT::showNum();
c1.showName();
c2.showName();
cin >> s;
c1.changeServeName(s);
c1.showName();
c2.showName();
return 0;
}
代码是这样的,然后编译不通过,报LNK2005和LNK1169
求大佬