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 8633497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:30:04+00:00 2026-06-12T09:30:04+00:00

Assuming I have this class: class Shape { public: int value; Shape(int v) :

  • 0

Assuming I have this class:

class Shape
{
public:
    int value;

    Shape(int v) : value(v) {};

    void draw()
    {
        cout << "Drawn the element with id: " << value << endl;
    }
};

and the following code (which works)

    Shape *myShapeObject = new Shape(22);

    void (Shape::*drawpntr)();
    drawpntr = &Shape::draw;

    (myShapeObject ->*drawpntr)();

I have a drawpntr function pointer to a void-returning 0-arguments function member of the class Shape.

First thing I’d like to ask:

drawpntr = &Shape::draw;

the function is a member function and there’s no object here.. what address does drawpntr receive? The class shouldn’t even exist

I agree with the line

(myShapeObject->*drawpntr)();

because I understand I cannot de-reference a function pointer to a member function (no object -> no function), but what address is actually stored in drawpntr?? There’s no object when the

drawpntr = &Shape::draw;

line is invoked.. and the class shouldn’t exist either as an entity

  • 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-12T09:30:05+00:00Added an answer on June 12, 2026 at 9:30 am

    All member functions share the same code, so they have the same address in the code segment of memory. Member functions operate on different instances only because they are implicitly passed different values of this pointer. They are not tied in any way to any of the instances on which they operate. The actual value of drawpntr could be determined statically if the function is non-virtual, or dynamically (through the vtable) if the function is virtual.

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

Sidebar

Related Questions

Assuming that I have objects similar to this: public class User { public int
Assuming I have an Entity Framework 4.2 class like this: class Company { public
Assuming I have a simple structure that looks like this: public class Range {
Assuming I have a class like this: class Database { public static $hostname =
Can I have a data contract of this shape?? [DataContract] public class YearlyStatistic{ [DataMember]
I have this code: list.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int
Assuming I have this HTML structure: <ul class='menu'> <li> <div></div> <div> <div></div> <div> <a
Suppose I have this structures in c++ : class A{ public: B b; }
Shape.h namespace Graphics { class Shape { public: virtual void Render(Point point) {}; };
Assuming that I have this navigation bar <div id = nav> <a class =

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.