Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7713691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:56:11+00:00 2026-06-01T01:56:11+00:00

I need to solve such a problem. There is a base class and two

  • 0

I need to solve such a problem.
There is a base class and two inherited classes. The base class contains method which needs a function-pointer as a parameter. But such functions are defined in inherited classes.

class CBase;

typedef bool (CBase::*FPredicate)();

class CBase
{
public:
    CBase() {}
    ~CBase() {}
protected:
    //this method waits until 'predicate' is true or until 'timeout' ms. passed
    //and returns true if 'predicate' is true eventually
    bool WaitEvent(FPredicate predicate, int timeout)
    {
        bool result = false;
        int time1 = GetTickCount();
        int time2;

        bool isEnd = false;
        while(!isEnd)
        {
            result = isEnd = (this->*predicate)();              

            time2 = GetTickCount();
            if(time2 - time1 > timeout && !isEnd)
                isEnd = true;
        }
        return result;
    }
};

class CChildA : public CBase
{
protected:
    bool a1() {/*some work*/}
    bool a2() {/*some work*/}
    void a_main()
    {
        ...
        WaitEvent(&CChildA::a1, 100);
        ...
        WaitEvent(&CChildA::a2, 100);
        ...
    }
};

class CChildB : public CBase
{
protected:
    bool b1() {/*some work*/}
    bool b2() {/*some work*/}
    void b_main()
    {
        ...
        WaitEvent(&CChildB::b1, 100);
        ...
        WaitEvent(&CChildB::b2, 100);
        ...
    }
};

MSVC 2005 compiler gives an error on WaitEvent calls:

error C2664: ‘CBase::WaitEvent’ : cannot convert parameter 1 from ‘bool (__thiscall CChildA::* )(void)’ to ‘FPredicate’

A question is: how shall I change the code to make it work? will it be safe to rewrite WaitEvent call as
WaitEvent((FPredicate)(&CChildA::a1), 100)?

In this case compiler tells of no error but is it safe? Or is there a better way of solving a problem?

Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T01:56:13+00:00Added an answer on June 1, 2026 at 1:56 am

    The problem is that the implicitly passed this differs in type. Either you cast it, but that will probably fail in the presence of multiple inheritance. A better & more robust solution would be to change the signature to:

    template< typename T >
    bool WaitEvent( bool ( T::*predicate )(), int timeout ) { ... }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to solve a problem within job booking software and am hoping to
I need to solve a job affectation problem and I would like to find
I need to solve a locking problem for this scenario: A multi CPU system.
I need to solve a system of linear equations in my program. Is there
A problem that we need to solve regularly at my workplace is how to
I don't like JSF but I need to solve this problem with it, I
To solve some problem I need to compute a variant of the pascal's triangle
I need a regular expression to solve the following problem (links to similar problems
I need to solve a computational problem that boils down to searching for reciprocally-nearest
I wonder if there any better ideas to solve the problem below, I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.