我想在我的类线程中使用另一个类对象。
我该如何实施?
我的实现:
.h文件
#pragma once
#include "class_A.h'
#include "class_B.h"
class MyClass
{
public:
MyClass();
~MyClass();
public:
static DWORD WINAPI _thread_use_another_class_object_(LPVOID lPvoid);
}
.cpp文件
DWORD WINAPI MyClass::_thread_use_another_class_object(LPVOID lPvoid)
{
DWORD dwCurrentTime = GetTickCount();
class_A *ca = new class_A; // I want to use class_A on here.
ca->bell_action(dwCurrentTime);
delete ca;
class_B *cb = new class_B;
cb->bell_action(dwCurrentTime);
delete cb;
}
class_A.h
class class_A
{
public:
class_A();
~class_A();
public:
DWORD bell_action(DWORD type);
DWORD make_sound(DWORD type);
};
class_A.cpp
DWORD class_A::bell_action(DWORD type)
{
DWORD sound_wave = type % 670;
make_sound(sound_wave);
return 0;
}
class_B与class_A相同
似乎太简单和容易理解了。但是我无法编译它,导致链接错误。
我在Windows 10 RS5 x64上使用VisualStudio 2010 SP1
MyClass.obj : error LNK2019 : unresolved external symbol "public: __thiscall class_A::class_A(void)" ..........