Location of member functions in memory

This is a discussion on Location of member functions in memory within the C++ Programming forums, part of the General Programming Boards category; Consider the following class: Code: class A { int Aint; void Afunc(void); }; void A::Afunc(void) { return; } The sizeof ...

  1. #1
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401

    Location of member functions in memory

    Consider the following class:
    Code:
    class A
    {
        int Aint;
        void Afunc(void);
    };
    
    void A::Afunc(void)
    { return; }
    The sizeof A is 4. The sizeof Aint is 4. Where is the code of Afunc stored when I make an instance of A? Also, is that code replicated for each instance of A, or is there just one set of code?
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    Well what do you think would make most sense from the information that you have worked out?
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571

    Re: Location of member functions in memory

    Originally posted by bennyandthejets

    is there just one set of code?
    Why would you ever need to have more than one set of code?
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  4. #4
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Yeah that fits. I think what I need right now is a description of the structure of an executable. I remember seeing that somewhere, so I will take a look around.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,662
    Remember that C++ member functions are just like C functions except they "this" passed to em implicitly.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Modules and Member Functions
    By arrgh in forum C++ Programming
    Replies: 2
    Last Post: 05-07-2008, 02:46 AM
  2. Static functions.... why?
    By patricio2626 in forum C++ Programming
    Replies: 4
    Last Post: 04-02-2007, 08:06 PM
  3. member functions can't see private data members
    By ichijoji in forum C++ Programming
    Replies: 2
    Last Post: 11-22-2006, 01:36 PM
  4. issue with member functions
    By Chaplin27 in forum C++ Programming
    Replies: 4
    Last Post: 09-27-2006, 09:18 PM
  5. Pointer's
    By xlordt in forum C Programming
    Replies: 13
    Last Post: 10-14-2003, 02:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21