-
How to make derived virtual member function in a _beginthread work?
I am trying to figure out a way to call the derived virtual member function
(test) for the _beginthread, which takes void(*pmf)(void*). Listed below
are the base/derived class defs. Read solution #2 (Danny Kalev - 10min0800.asp)
but could't figure out for this scenario. Any suggestion?
#include <iostream.h>
#include <windows.h>
class BaseClass
{
public:
BaseClass(void) {};
virtual ~BaseClass(){};
virtual void test(void) = 0;
private:
};
class DerivedClassA : virtual public BaseClass
{
public:
DerivedClassA(void){};
virtual ~DerivedClassA() {};
virtual void test(void) {};
protected:
private:
};
void main(void)
{
BaseClass *cTab;
cTab = new DerivedClassA();
cTab->test();
return;
}
Regards,
Jonathan
-
Re: How to make derived virtual member function in a _beginthread work?
Hi!
you wrote:
BaseClass *cTab;
cTab = new DerivedClassA();
cTab->test();
try this one:
DerivedClassA *cTab;
cTab = new DerivedClassA();
cTab->test();
How would the compiler know which one of your virtual member functions to
call?
"Jonathan" <jjb@nasa2.ksc.nasa.gov> wrote:
>
>I am trying to figure out a way to call the derived virtual member function
>(test) for the _beginthread, which takes void(*pmf)(void*). Listed below
>are the base/derived class defs. Read solution #2 (Danny Kalev - 10min0800.asp)
>but could't figure out for this scenario. Any suggestion?
>
>#include <iostream.h>
>#include <windows.h>
> class BaseClass
> {
> public:
> BaseClass(void) {};
> virtual ~BaseClass(){};
> virtual void test(void) = 0;
> private:
> };
>
> class DerivedClassA : virtual public BaseClass
> {
> public:
> DerivedClassA(void){};
> virtual ~DerivedClassA() {};
> virtual void test(void) {};
> protected:
> private:
> };
>
> void main(void)
> {
> BaseClass *cTab;
> cTab = new DerivedClassA();
> cTab->test();
> return;
> }
>
>
> Regards,
> Jonathan
>
-
Re: How to make derived virtual member function in a _beginthread work?
Yes, it will call the right class, but I am still trying to figure out how
to call a virtual member function of the derived class in _beginthread call.
Regards,
Jonathan
"Johnny" <p166@freemail.hu> wrote:
>
>Hi!
>
>you wrote:
>BaseClass *cTab;
>cTab = new DerivedClassA();
>cTab->test();
>
>try this one:
>
>DerivedClassA *cTab;
>cTab = new DerivedClassA();
>cTab->test();
>
>How would the compiler know which one of your virtual member functions to
>call?
>
>"Jonathan" <jjb@nasa2.ksc.nasa.gov> wrote:
>>
>>I am trying to figure out a way to call the derived virtual member function
>>(test) for the _beginthread, which takes void(*pmf)(void*). Listed below
>>are the base/derived class defs. Read solution #2 (Danny Kalev - 10min0800.asp)
>>but could't figure out for this scenario. Any suggestion?
>>
>>#include <iostream.h>
>>#include <windows.h>
>> class BaseClass
>> {
>> public:
>> BaseClass(void) {};
>> virtual ~BaseClass(){};
>> virtual void test(void) = 0;
>> private:
>> };
>>
>> class DerivedClassA : virtual public BaseClass
>> {
>> public:
>> DerivedClassA(void){};
>> virtual ~DerivedClassA() {};
>> virtual void test(void) {};
>> protected:
>> private:
>> };
>>
>> void main(void)
>> {
>> BaseClass *cTab;
>> cTab = new DerivedClassA();
>> cTab->test();
>> return;
>> }
>>
>>
>> Regards,
>> Jonathan
>>
>
-
Re: How to make derived virtual member function in a _beginthread work?
Read the _beginthread, beginthreadex function documentation in Visual C++
Documentation section in MSDN.
"Jonathan" <jjb@nasa2.ksc.nasa.gov> wrote:
>
>Yes, it will call the right class, but I am still trying to figure out how
>to call a virtual member function of the derived class in _beginthread call.
>
>
>Regards,
>Jonathan
>
>"Johnny" <p166@freemail.hu> wrote:
>>
>>Hi!
>>
>>you wrote:
>>BaseClass *cTab;
>>cTab = new DerivedClassA();
>>cTab->test();
>>
>>try this one:
>>
>>DerivedClassA *cTab;
>>cTab = new DerivedClassA();
>>cTab->test();
>>
>>How would the compiler know which one of your virtual member functions
to
>>call?
>>
>>"Jonathan" <jjb@nasa2.ksc.nasa.gov> wrote:
>>>
>>>I am trying to figure out a way to call the derived virtual member function
>>>(test) for the _beginthread, which takes void(*pmf)(void*). Listed below
>>>are the base/derived class defs. Read solution #2 (Danny Kalev - 10min0800.asp)
>>>but could't figure out for this scenario. Any suggestion?
>>>
>>>#include <iostream.h>
>>>#include <windows.h>
>>> class BaseClass
>>> {
>>> public:
>>> BaseClass(void) {};
>>> virtual ~BaseClass(){};
>>> virtual void test(void) = 0;
>>> private:
>>> };
>>>
>>> class DerivedClassA : virtual public BaseClass
>>> {
>>> public:
>>> DerivedClassA(void){};
>>> virtual ~DerivedClassA() {};
>>> virtual void test(void) {};
>>> protected:
>>> private:
>>> };
>>>
>>> void main(void)
>>> {
>>> BaseClass *cTab;
>>> cTab = new DerivedClassA();
>>> cTab->test();
>>> return;
>>> }
>>>
>>>
>>> Regards,
>>> Jonathan
>>>
>>
>
-
Re: How to make derived virtual member function in a _beginthread work?
Johnny,
Thanks for your response. But what I am really trying to make the derived
virtual member function call within the _beginthread call. As I stated initally
I read and tried a solution #2(non-static call method) of Danny Kalev for
this case and found that it will not work for the virtual member function.
Yes, I read the Visual C++ doc. and know how to call it. Thanks again but
can someone else give a try.
Regards,
Jonathan
"Johnny" <p166@freemail.hu> wrote:
>
>Read the _beginthread, beginthreadex function documentation in Visual C++
>Documentation section in MSDN.
>
>"Jonathan" <jjb@nasa2.ksc.nasa.gov> wrote:
>>
>>Yes, it will call the right class, but I am still trying to figure out
how
>>to call a virtual member function of the derived class in _beginthread
call.
>>
>>
>>Regards,
>>Jonathan
>>
>>"Johnny" <p166@freemail.hu> wrote:
>>>
>>>Hi!
>>>
>>>you wrote:
>>>BaseClass *cTab;
>>>cTab = new DerivedClassA();
>>>cTab->test();
>>>
>>>try this one:
>>>
>>>DerivedClassA *cTab;
>>>cTab = new DerivedClassA();
>>>cTab->test();
>>>
>>>How would the compiler know which one of your virtual member functions
>to
>>>call?
>>>
>>>"Jonathan" <jjb@nasa2.ksc.nasa.gov> wrote:
>>>>
>>>>I am trying to figure out a way to call the derived virtual member function
>>>>(test) for the _beginthread, which takes void(*pmf)(void*). Listed below
>>>>are the base/derived class defs. Read solution #2 (Danny Kalev - 10min0800.asp)
>>>>but could't figure out for this scenario. Any suggestion?
>>>>
>>>>#include <iostream.h>
>>>>#include <windows.h>
>>>> class BaseClass
>>>> {
>>>> public:
>>>> BaseClass(void) {};
>>>> virtual ~BaseClass(){};
>>>> virtual void test(void) = 0;
>>>> private:
>>>> };
>>>>
>>>> class DerivedClassA : virtual public BaseClass
>>>> {
>>>> public:
>>>> DerivedClassA(void){};
>>>> virtual ~DerivedClassA() {};
>>>> virtual void test(void) {};
>>>> protected:
>>>> private:
>>>> };
>>>>
>>>> void main(void)
>>>> {
>>>> BaseClass *cTab;
>>>> cTab = new DerivedClassA();
>>>> cTab->test();
>>>> return;
>>>> }
>>>>
>>>>
>>>> Regards,
>>>> Jonathan
>>>>
>>>
>>
>
-
Re: How to make derived virtual member function in a _beginthread work?
void ThreadFunc(void* ptr)
{
Base* pB = reinterpret_cast<Base*>(ptr);
pB->test();
}
main()
{
Derived* pD = new Derived;
_beginThread(ThreadFunc, 0 , pD);
}
--
Truth,
James Curran
www.NJTheater.com (Professional)
www.NovelTheory.com (Personal)
www.BrandsForLess.Com (Day Job)
"Jonathan" <jjb@nasa2.ksc.nasa.gov> wrote in message
news:3bb8d148$1@news.devx.com...
>
> I am trying to figure out a way to call the derived virtual member
function
> (test) for the _beginthread, which takes void(*pmf)(void*). Listed below
> are the base/derived class defs. Read solution #2 (Danny Kalev -
10min0800.asp)
> but could't figure out for this scenario. Any suggestion?
>
> #include <iostream.h>
> #include <windows.h>
> class BaseClass
> {
> public:
> BaseClass(void) {};
> virtual ~BaseClass(){};
> virtual void test(void) = 0;
> private:
> };
>
> class DerivedClassA : virtual public BaseClass
> {
> public:
> DerivedClassA(void){};
> virtual ~DerivedClassA() {};
> virtual void test(void) {};
> protected:
> private:
> };
>
> void main(void)
> {
> BaseClass *cTab;
> cTab = new DerivedClassA();
> cTab->test();
> return;
> }
>
>
> Regards,
> Jonathan
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks