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

  • Home
  • SEARCH
  • 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 8524193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:37:14+00:00 2026-06-11T07:37:14+00:00

Code class cat{ public: void walk(){ printf(cat is walking \n); } void myAbc(){ void

  • 0

Code

class cat{

        public:
           void walk(){
                printf("cat is walking \n");
           }

           void myAbc(){
               void (*pKoo)();
               pKoo = &this->walk;
           }

          void myDef(){
               void(cat::*pFoo)();
               pFoo = &this->walk;
          }
        }

    };

Result

  1. void (*pKoo)(); – No problem
  2. pKoo = &this->walk; – Compiling error
  3. void(cat::*pFoo)(); – No problem
  4. pFoo = &this->walk; – compile error;

Question

  • Why no 2 impossible? If Impossible, Then what is the use of No 1?
  • Why no 4 impossible? If Impossible, Then what is the use of No 3?

Please help for conceptual explanation. thank you

  • 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-11T07:37:16+00:00Added an answer on June 11, 2026 at 7:37 am

    Why no 2 impossible?

    My compiler gives an error message:

    cannot convert ‘void (cat::*)()’ to ‘void (*)()’ in assignment
    

    meaning that you can’t convert a pointer-to-member-function to a pointer-to-function. They are incompatible types; a pointer-to-function can be called directly, while a pointer-to-member-function needs to be applied to an object. So the type you assign to has to be pointer-to-member-function, or void (cat::*)();, as you correctly use in 3.

    If Impossible, Then what is the use of No 1?

    It’s used to store a pointer to a static or non-member function.

    Why no 3 impossible?

    (I assume you mean 4, not 3.) My compiler gives an error message:

    ISO C++ forbids taking the address of a bound member function to form a 
    pointer to member function.  Say ‘&cat::walk’
    

    For some reason, you’re not allowed to take the address of a member function using an object (or pointer); you have to use the class name instead. We can only speculate on why this isn’t allowed; perhaps because it’s not entirely clear which override should be chosen if it’s virtual, or perhaps for some other reason.

    Whatever the reason, use the allowed syntax: pFoo = &cat::walk;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: class Test { public static void main(String[] args) {
I have the following code: public class Test { public static void Main() {
Code: class JobsManager(models.Manager): def get_active_by_category(self, cat, limit): import datetime from django.db.models import Q return
I have the code: class Point3D{ protected: float x; float y; float z; public:
I have this code: class LFSeq: # lazy infinite sequence with new elements from
I have this code: class SomeClass: @classmethod def func1(cls,arg1): #---Do Something--- @classmethod def func2(cls,arg1):
I have the following code :- class A : public B { public: _container
I am using this code to check whether a database already exists: public static
Hi All I have the following code: enter code here public class XMPPClient extends
Given the following code: public enum Pet { Cat, Dog } public interface IOwner

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.