Re: [Dev-C++] About member functions
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
From: Jason H. <jas...@bt...> - 2001-11-01 01:43:28
|
MessageI think in general that it being called a pointer to a member is = quite misleading. I'm not sure in what you say whether I have convinced = you of my point of view or that you are sticking to the idea of a = function to each object. Of course everything we have talked about is = pretty implementation specific, but they will all tend towards the same = systems, with only minor differences. You will note that he says it is = like an offset he doesn't say it is an offset. I believe he is using the = idea of offsets and such as an analogy, which is misleading in it's own = way. He does say that it is up to the compiler to interpret the pointer = in the correct way depending upon what is being referenced. Jason.=20 ----- Original Message -----=20 From: Ioannis Vranos=20 To: Dev-C++=20 Sent: Thursday, November 01, 2001 1:26 AM Subject: RE: [Dev-C++] About member functions Yes for virtual functions the pointer is used an an array index (he = has a picture). For non virtual functions it acts like an offset. If it = helps, he says that we can pass a pointer to a virtual function between = address space, but we can not exchange a pointer to a non-virtual = function between address spaces. Special Edition and 3rd edition *are* the same. If your printing is = not recent it simply lacks only some appendixes at the end of the book = which you can download online as pdfs from Stroustrup's pages, so go to = his site and check. I found your quote. What i say is on page 420 the draw and the first = paragraph. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.f2s.com * Alternative URL: http://run.to/noicys -----Original Message----- From: dev...@li... = [mailto:dev...@li...] On Behalf Of Jason = Hardman Sent: Thursday, November 01, 2001 2:58 AM To: Dev-C++ Subject: Re: [Dev-C++] About member functions I am not a pro for a start, but because of my background I tend to = understand some of the concepts in Classes and Objects from a different = perspective. My background being as a hardware engineer and using = assembler (68000 mainly). The section you are refering to is about pointers to member = functions. Something that a class can do is provide a table of pointers = to it's member functions in it's internal representation. There will = still be only one instance of the member funstion, but each object will = contain a pointer to that fuction. This is specifically needed in the = case of virtual member functions where the caller doesn't necessarily = know what class it is using. By saying that a particular pointer to the = member is at such and such a position in an object then you can = indirectly call the correct function for the object. Pointers to = pointers are a useful form of indirection. In essence what that paragraph is saying is that if you call method = 5 (for example) of an object the compiler will know that it actualy = refers to a particular function in a particular place in memory, or at = least a pointer to that function in memory. I will qoute from my edition (third) on the same page you quote: "C++ offers a facility for indirectly referring to member of a = class. A pointer to a member is a *value* that identifies a member of a = class. You can think of it as the position of the member in an object of = the class, but of course an implementation takes into account the = differences between data members, virtual functions, non-virtual = functions, etc." Does that seem reasonable to you? It seems that we are looking at = the same paragraphs and getting two totally different answers from it. Jason. ----- Original Message -----=20 From: Ioannis Vranos=20 To: Dev-C++=20 Sent: Wednesday, October 31, 2001 8:11 PM Subject: [Dev-C++] About member functions This subject has been discussed on th e past, but now new evidence = came up. :) In "The C++ Programming Language" Special Edition on page 419 it = says that each object has its own member function as i was claiming in = the beginning. It says many things but lets concentrate at the end of that page: "Just like ordinary pointers to functions, pointers to member = functions are used when we need to refer to a function without having to = know its name. However, a pointer to member isn't a pointer to a piece = of memory the way a pointer to a variable or a pointer to a function is. = It is more like an offfset into a structure or an index into an array. = When a pointer to member is combined with a pointer to an object of the = right type, it yields something that identifies a particular member of a = particular object". i think we were discussing it with Jason Hardman. Jason if you see = it, please tell me your opinion (since you seem you are a pro). Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.f2s.com * Alternative URL: http://run.to/noicys |