如何实现这个程序,大家可以给我点思路吗,我不知道怎么去实现,觉得好乱
这个我记得我写过
https://ask.csdn.net/questions/7948514/54207147
// Client.h
#pragma once
#include <string>
using namespace std;
class cClient {
private:
static string ServerName;
static int ClientNum;
static string Name;
public:
static void SetServerName(const string& newServerName);
static string GetServerName();
static void SetName(const string& newName);
static string GetName();
};
// Client.cpp
#include "Client.h"
string cClient::ServerName = "";
int cClient::ClientNum = 0;
string cClient::Name = "";
void cClient::SetServerName(const string& newServerName) {
ServerName = newServerName;
}
string cClient::GetServerName() {
return ServerName;
}
void cClient::SetName(const string& newName) {
Name = newName;
}
string cClient::GetName() {
return Name;
}
// Test.cpp
#include <iostream>
#include "Client.h"
using namespace std;
int main() {
cClient::SetServerName("Server 1");
cout << "Server Name: " << cClient::GetServerName() << endl;
cClient::SetName("User 1");
cout << "Name: " << cClient::GetName() << endl;
return 0;
}