473,789 Members | 2,740 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

inheritance and memory layout

given:
class A {
// ...
};

class B : public class A {
// ...
}

void some_fun()
{
B b;
A *pa = &b;
B *pb = &b;

if ((void *)pa == (void *)pb) {
;
} else {
// is it possible ??
;
}
}

is it guarantee (from the standard), assuming single inheritance, that it is
impossible to reach the else statement in the above code?
Jul 23 '05 #1
2 2279
With single inheritance, yes it is impossible to reach the else
statement.

The following article should help:

http://www.eventhelix.com/RealtimeMa...rformance2.htm

Deepa
--
EventStudio 2.5 - http://www.EventHelix.com/EventStudio
Generate Sequence diagrams from a simple declarative language

Jul 23 '05 #2
The said link just presents one way of implementing virtual functions.
I dont think standard says anything about how to implement virtual
functions.

The OP had asked in case of singled inheritance if else branch can be
true.

I think it can be if the user overloads & operator for B and does
something crazy

raj

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
12921
by: Steve Jorgensen | last post by:
Recently, I tried and did a poor job explaining an idea I've had for handling a particular case of implementation inheritance that would be easy and obvious in a fully OOP language, but is not at all obvious in VBA which lacks inheritance. I'm trying the explanation again now. I often find cases where a limited form of inheritance would eliminate duplication my code that seems impossible to eliminate otherwise. I'm getting very...
3
41539
by: enchantingdb | last post by:
I have an exam tomorrow that covers the perceived advantages and disadvantages of object oriented programming, in particular polymorphism, inheritance and encapsulation. I know the advantages but am not clear on the disadvantages. I have had a look on the Web and in newsgroups but couldn't find much. As time is running out, I thought I would post here and hope that someone would reply. Thanks Rob
5
2050
by: Invalidlastname | last post by:
Hi, I just read the pattern "Design and Implementation Guidelines for Web Clients" from MSDN. Here is my question. In chapter 3, http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/diforwc-ch03.asp , the article mentions using page inheritance to maintain common page layout. We currently use page inheritance approach to segment the function areas. In each function area, there is a base page to provide the common...
6
2102
by: VR | last post by:
Hi, I read about Master Pages in ASP.Net 2.0 and after implementing some WinForms Visual Inheritance I tryed it with WebForms (let's say .aspx pages, my MasterPage does not have a form tag itself so, cannot be called a WebForm itself, the child pages will implement forms). I created a Master.aspx page and removed all HTML from it, added some code to the .aspx.vb file to add controls to my page. Then I created a Child.aspx and changed the...
0
1837
by: Edsko de Vries | last post by:
Hi, I wrote an article that may be of interest to some people in this newsgroup. It explains the memory (object) layout for multiple and virtual inheritance. The article can be read at http://www.phpcompiler.org/doc/virtualinheritance.html If anyone has any corrections or suggestions for improvements, I'd appreciate it.
3
292
by: junw2000 | last post by:
Below is a simple code about multiple inheritance #include <iostream> class A{ int x; }; class B{ int y;
1
3180
by: stasgrom | last post by:
Guys, I have this situation: the class C is defined as follow: class C: public A, public B {...}; Now when I create an object of class C, I can see that the compiler (VS 8.0) decides to layout the memory of this object so that the fields of class B come before the fields of class A. I always thought the layout is defined by the order of inheritance. Was I wrong? Thanks.
0
1426
by: Ge Chunyuan | last post by:
hi: Just out of curiosity, more than 10 years passed since Stanley B. Lippman's <<Inside the C++ Object Model>>. Is there anything changed these days? Eg, the "Memory Layout for Multiple and Virtual Inheritance" Could anyone give some comments on the mainstream compiler strategy for it?
3
1795
by: =?Utf-8?B?RnJhbmsgVXJheQ==?= | last post by:
Hi all It is maybe a stupid question, but I have some trouble with Inheritance. For example: I create a new class with one form. On this form I place on the bottom a Panel and on this Panel on the right side a button. On both controls I set Anchor (bottom, right).
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9984
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7529
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4093
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3701
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.