m0_67644151 2022-05-25 13:13 采纳率: 66.7%
浏览 30
已结题

创建类时LNK2005错误

5.cpp

#include <iostream>
#include <thread>
#include <time.h>
#include <Windows.h>
#include "Header.h"
#include "Pause.cpp"

int main()
{
    using namespace std;
    cout << "\033[37m";    // reset font color to black
    thread skipping(skip);
    introduction.Run();
    return 0;
}

Header.h

// control
#define UP 1
#define DOWN 2
#define LEFT 3
#define RIGHT 4
#define CW 5    // CW: clockwise
#define CCW 6    // CCW: counterclockwise 

// display
extern int start();
extern void cout_in_turn(char letters[], int sum, int sleep);

// pause
extern int skip();

Pause.cpp

#include <condition_variable>
#include <mutex>
#include <thread>
#include <Windows.h>
#include "Header.h"

#define KEY_DOWN(vKey) ((GetAsyncKeyState(vKey) & 0x8000) ? 1:0)    //GetAsyncKeyState函数中的KEY_DOWN
using namespace std;
class SkipThread
{
public:
    SkipThread() = default;

public:
    void Run();
    void Stop();
    void Pause(); //暂停
    void Resume();//恢复
private:
    condition_variable m_cv;
    mutex mu;
    bool m_isStop{ false };
    bool m_isPause{ false };
    atomic<int> num = 0;
};
void SkipThread::Run()
{
    start();
}
void SkipThread::Stop()
{
    m_isStop = true;
}
void SkipThread::Pause()
{
    unique_lock<mutex> lock(mu);
    m_isPause = true;
    m_cv.notify_one();
}
void SkipThread::Resume()
{
    unique_lock<mutex> lock(mu);
    m_isPause = false;
    m_cv.notify_one();
}
SkipThread introduction;

int skip()
{
    while (1)
    {
        if (KEY_DOWN(220))  // 220 is "\"
        introduction.Pause();
        return 0;
    }
}

(Display.cpp)

#include <iostream>
#include <thread>
#include <Windows.h>
#include "Header.h"

int start()
{
    /* This is a Tetris game.
     * You can use your keyboard to control the tetris falling from the top of the screen.
     * 
     * Here is the operating instructions.
     * You can press "\" to skip the instruction.
     * 
     * S: move down
     * A: move left
     * D: move right
     * Q: Rotate 90° counterclockwise
     * E: Rotate 90° clockwise
     * 
     * WARNING: You can't use W to move the tetris up!        (this is shown in yellow)
     */
    using namespace std;
    static char a[23] = { "T""h""i""s"" ""i""s"" ""a"" ""T""e""t""r""i""s"" ""g""a""m""e""." };
    static char b[84] = { "Y""o""u"" ""c""a""n"" ""u""s""e"" ""y""o""u""r"" ""k""e""y""b""o""a""r""d"" ""t""o"" ""c""o""n""t""r""o""l"" ""t""h""e"" ""t""e""t""r""i""s"" ""f""a""l""l""i""n""g"" ""f""r""o""m"" ""t""h""e"" ""t""o""p"" ""o""f"" ""t""h""e"" ""s""c""r""e""e""n""." };
    static char c[36] = { "H""e""r""e"" ""i""s"" ""t""h""e"" ""o""p""e""r""a""t""i""n""g"" ""i""n""s""t""r""u""c""t""i""o""n""s""." };
    static char d[43] = { "Y""o""u"" ""c""a""n"" ""p""r""e""s""s"" ""\"""\\""\""" ""t""o"" ""s""k""i""p"" ""t""h""e"" ""i""n""s""t""r""u""c""t""i""o""n""." };
    static char e[13] = { "S"":"" ""m""o""v""e"" ""d""o""w""n" };
    static char f[13] = { "A"":"" ""m""o""v""e"" ""l""e""f""t" };
    static char g[14] = { "D"":"" ""m""o""v""e"" ""r""i""g""h""t" };
    static char h[33] = { "Q"":"" ""r""o""t""a""t""e"" ""9""0""d""e""g"" ""c""o""u""n""t""e""r""c""l""o""c""k""w""i""s""e" };
    static char j[26] = { "E"":"" ""r""o""t""a""t""e"" ""9""0""d""e""g"" ""c""l""o""c""k""w""i""s""e" };
    static char k[49] = { "W""A""R""N""I""N""G"":"" ""Y""o""u"" ""c""a""n""\'""t"" ""u""s""e"" ""\"""W""\""" ""t""o"" ""m""o""v""e"" ""t""h""e"" ""t""e""t""r""i"" ""u""p""!" };

    // Cout every letter in each array in turn
    cout_in_turn(a, 23, 800);
    cout_in_turn(b, 84, 1000);
    cout << endl;
    cout_in_turn(c, 36, 400);
    cout_in_turn(d, 43, 1000);
    cout << endl;
    thread t1(skip);
    cout_in_turn(e, 13, 200);
    cout_in_turn(f, 13, 200);
    cout_in_turn(g, 14, 200);
    cout_in_turn(h, 33, 200);
    cout_in_turn(j, 26, 600);
    cout << endl;
    for (int i = 0; i <= 48; i++)
    {
        cout << "\033[33m" << k[i];    // turn to yellow
        Sleep(40);
    }
    Sleep(1000);
    cout << "\033[37m" << endl;        // trun back to white

    return 0;
}

void cout_in_turn(char letters[], int sum, int sleep)
{
    using namespace std;
    for (int i = 0; i <= sum - 1; i++)
    {
        cout << letters[i];
        Sleep(40);
    }
    Sleep(sleep);
    cout << endl;
}

img

请问是哪里出了什么问题?

  • 写回答

1条回答

      报告相同问题?

      问题事件

      • 系统已结题 6月2日
      • 已采纳回答 5月25日
      • 创建了问题 5月25日

      悬赏问题

      • ¥15 和您碰到了同一个问题
      • ¥15 如何在微信支付V3PHP版请求中添加header?
      • ¥15 在数字信号处理中用MATLAB显示波形。
      • ¥15 keil MDK软件进行仿真调试的局限
      • ¥15 关于gateway产生临时文件夹的问题
      • ¥15 Java Broken Pipe以及OOM
      • ¥20 请问有没有RTL8211FS的参考原理图
      • ¥50 esp32的platfromio工程添加文件就会编译失败
      • ¥15 linux下运行VASP报错
      • ¥15 python里面查找赋值,如何可以在剩余未空值的行里面进行进一步的筛选呢?