473,387 Members | 3,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

polymorphic class have diferent size on different os

class B
{
public :
void f() = 0 ;
};

class D : public B
{
public :
void f()
{

}
};

int main()
{
D d ;
int s = sizeof(d);
return 0 ;
}

now value of s will be different on windows and unix , why so ?

Jun 29 '06 #1
5 1043
mangesh wrote:
class B
{
public :
void f() = 0 ;
This isn't valid, virtual keyword is missing. };

class D : public B
{
public :
void f()
{

}
};

int main()
{
D d ;
int s = sizeof(d);
return 0 ;
}

now value of s will be different on windows and unix , why so ?

Who says they should be the same?

--
Ian Collins.
Jun 29 '06 #2

mangesh wrote:
class B
{
public :
void f() = 0 ;
virtual void f() = 0;
};

class D : public B
{
public :
void f()
{

}
};

int main()
{
D d ;
int s = sizeof(d);
return 0 ;
}

now value of s will be different on windows and unix , why so ?


Unix is a 64 bit OS and your windows is probably 32 bit.
Regardless, a real programmer must not write code that depends on the
platform beneath.
Hence: what you see is expected and inconsequential.

Jun 29 '06 #3
mangesh wrote:

now value of s will be different on windows and unix , why so ?


There's not even any guarantee that s will be the same value on
different implementations within UNIX or Windows.

Jun 29 '06 #4
mangesh posted:

now value of s will be different on windows and unix , why so ?

Three reasons:
(1) The amount of bytes consumed by primitive types is implementation-
specific.
(2) The amount and placement of padding within an object is
implementation-specific.
(3) The way in which virtual functions are implemented is
implementation-specific.

--

Frederick Gotham
Jun 29 '06 #5
Hi ,
thanks for detailed reply .

Regards ,
Mangesh Sawant .

Frederick Gotham wrote:
mangesh posted:

now value of s will be different on windows and unix , why so ?

Three reasons:
(1) The amount of bytes consumed by primitive types is implementation-
specific.
(2) The amount and placement of padding within an object is
implementation-specific.
(3) The way in which virtual functions are implemented is
implementation-specific.

--

Frederick Gotham


Jun 30 '06 #6

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

Similar topics

37
by: Mike Meng | last post by:
hi all, I'm a newbie Python programmer with a C++ brain inside. I have a lightweight framework in which I design a base class and expect user to extend. In other part of the framework, I heavily...
9
by: Dave | last post by:
What is the expected output of this program and why??? #include <iostream> using namespace std; class base {
20
by: verec | last post by:
One problem I've come accross in designing a specific version of auto_ptr is that I have to disntiguish between "polymorphic" arguments and "plain" ones, because the template has to, internally,...
7
by: Mr. Ed | last post by:
I have a base class which has about 150 derived classes. Most of the derived classes are very similar, and many don't change the base class at all. All the derived classes have a unique factory...
7
by: James Fortune | last post by:
In response to different users or situations (data context) I transform the appearance and characteristics of Access Forms through code. This seems to fit in with the idea of polymorphism. Do...
12
by: Bob | last post by:
Hi, 'Shadowed' properties are not polymorphic. (See thread 'Inheritance and late binding') They should be. Problem: Base class has read only property 'X'. Derived class must have read / write...
5
by: FefeOxy | last post by:
Hi, > I'm having a debug assertion error within the file dbgdel.cpp with the expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) I traced the origin of the error and it happened as I tried to...
11
by: Angus | last post by:
I am developing a server which receives a range of different messages. There are about 12 different message types so I thought that a good idea would be to devise a class for each message type....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.