0

I want to use another class object in my class thread.
How can I implement it?

My implementation:

.h file

#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 file

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 is the same as class_A

It seems like too simple and easy to understand. But I cannot compile it, cause of link error.
I am using VisualStudio 2010 SP1 on Windows 10 RS5 x64

MyClass.obj : error LNK2019 : unresolved external symbol "public: __thiscall class_A::class_A(void)" ..........
AleXelton
  • 767
  • 5
  • 27
  • Seems as if you do not provide/link the definition of you `class_A` class. – t.niese Jan 15 '19 at 16:45
  • 3
    This has nothing to do with threads. The error simply says that it can't find the definition of class_A. – Adham Zahran Jan 15 '19 at 16:46
  • Or more accurately it can't find the definition of the default constructor. Make sure you properly link the lib that defines class_A. And make sure the default constructor is defined (not deleted) or be sure to define a constructor yourself. – Adham Zahran Jan 15 '19 at 16:47
  • @AdamZahran "Nothing to do with threads", what does it mean. I can't understand. I added declaration of `class_A` on the post. – AleXelton Jan 15 '19 at 16:52
  • Also, this error occurring only on thread. – AleXelton Jan 15 '19 at 16:55
  • Could you create an [MVCE](https://stackoverflow.com/help/mcve)? – Adham Zahran Jan 15 '19 at 19:49
  • "Nothing to do with threads" means that using threads or not is not related to the error. The error is caused by something else but you falsely related that to using threads. An MVCE will probably make the issue clearer to you, if not please post it here and we'll be able to assist you further :D – Adham Zahran Jan 15 '19 at 19:56

0 Answers0