Difference between class and struct with regards to padding and inheritanceWhy is there not an std::is_struct type trait?Adding a default constructor to a base class changes sizeof() a derived typeWhat is the difference between #include <filename> and #include “filename”?What are the differences between a pointer variable and a reference variable in C++?What are the differences between struct and class in C++?What is the difference between g++ and gcc?Difference between 'struct' and 'typedef struct' in C++?Difference between private, public, and protected inheritanceWhat is the difference between const int*, const int * const, and int const *?Image Processing: Algorithm Improvement for 'Coca-Cola Can' RecognitionWhat is the difference between 'typedef' and 'using' in C++11?Difference between `constexpr` and `const`
My employer is refusing to give me the pay that was advertised after an internal job move
Why are we moving in circles with a tandem kayak?
Wrapping IMemoryCache with SemaphoreSlim
Trying to open a new ubuntu terminal window from the existing window
Why does Canada require bilingualism in a lot of federal government posts?
Why was the LRV's speed gauge displaying metric units?
What is the German equivalent of the proverb 水清ければ魚棲まず (if the water is clear, fish won't live there)?
Is it okay for me to decline a project on ethical grounds?
Can a US President, after impeachment and removal, be re-elected or re-appointed?
Is The Venice Syndrome documentary cover photo real?
Why tantalum for the Hayabusa bullets?
Employer stores plain text personal data in a 'data warehouse'
How does the Thief's Fast Hands feature interact with mundane and magical shields?
Is there a word to describe someone who is, or the state of being, content with hanging around others without interacting with them?
Why is softmax function used to calculate probabilities although we can divide each value by the sum of the vector?
Shouldn't there be "us" instead of "our" in this sentence?
How do I make my photos have more impact?
Was Donald Trump at ground zero helping out on 9-11?
GNU sort stable sort when sort does not know sort order
What force enables us to walk? Friction or normal reaction?
How to season a character?
What is an Accessible Word?
How does a poisoned arrow combine with the spell Conjure Barrage?
Why did Windows 95 crash the whole system but newer Windows only crashed programs?
Difference between class and struct with regards to padding and inheritance
Why is there not an std::is_struct type trait?Adding a default constructor to a base class changes sizeof() a derived typeWhat is the difference between #include <filename> and #include “filename”?What are the differences between a pointer variable and a reference variable in C++?What are the differences between struct and class in C++?What is the difference between g++ and gcc?Difference between 'struct' and 'typedef struct' in C++?Difference between private, public, and protected inheritanceWhat is the difference between const int*, const int * const, and int const *?Image Processing: Algorithm Improvement for 'Coca-Cola Can' RecognitionWhat is the difference between 'typedef' and 'using' in C++11?Difference between `constexpr` and `const`
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
All of the below will be done on GCC 9.1 using Compiler Explorer, in x86-64, using -O3.
I have this code:
struct Base
Base()
double foo;
int bar;
;
struct Derived : public Base
int baz;
;
int main(int argc, char** argv)
return sizeof(Derived);
https://godbolt.org/z/OjSCZB
It correctly returns 16, as I would expect, 8 bytes for foo, and 4 bytes for bar and 4 bytes for baz. This works only because Derived inherits from Base and so it does not have to pad after bar due to Derived being a single type containing both Base and Derived elements.
I have two questions, as below:
First question
If I remove the explicit constructor of Base() , it starts returning 24, instead of 16. i.e. it adds padding after bar and baz.
https://godbolt.org/z/0gaN5h
I can't explain why having an explicit default constructor is any different to having an implicit default constructor.
Second question
If I then change struct to class for Base, it changes back to returning 16. I can not explain this either. Why would the access modifiers change the size of the structure?
https://godbolt.org/z/SCYKwL
c++ c++11 gcc
|
show 1 more comment
All of the below will be done on GCC 9.1 using Compiler Explorer, in x86-64, using -O3.
I have this code:
struct Base
Base()
double foo;
int bar;
;
struct Derived : public Base
int baz;
;
int main(int argc, char** argv)
return sizeof(Derived);
https://godbolt.org/z/OjSCZB
It correctly returns 16, as I would expect, 8 bytes for foo, and 4 bytes for bar and 4 bytes for baz. This works only because Derived inherits from Base and so it does not have to pad after bar due to Derived being a single type containing both Base and Derived elements.
I have two questions, as below:
First question
If I remove the explicit constructor of Base() , it starts returning 24, instead of 16. i.e. it adds padding after bar and baz.
https://godbolt.org/z/0gaN5h
I can't explain why having an explicit default constructor is any different to having an implicit default constructor.
Second question
If I then change struct to class for Base, it changes back to returning 16. I can not explain this either. Why would the access modifiers change the size of the structure?
https://godbolt.org/z/SCYKwL
c++ c++11 gcc
3
Half a dupe of stackoverflow.com/q/47914612/560648. I don't know why changing the keyword introducing the base would make a difference though (given that there's no member re-ordering going on anyway so differing member access levels oughtn't come into it)
– Lightness Races in Orbit
Jul 19 at 14:08
Ah thanks! That answer the first question, but not the second
– Salgar
Jul 19 at 14:10
4
Re: "It correctly returns 16, as I would expect" -- by definition, the result ofsizeofis correct, regardless of what you expect.
– Pete Becker
Jul 19 at 14:11
Hmm yeah it's the access specifier; addpublic:.
– Lightness Races in Orbit
Jul 19 at 14:12
1
@LightnessRacesinOrbit not a bug. Aggregates can't have private members
– NathanOliver
Jul 19 at 14:13
|
show 1 more comment
All of the below will be done on GCC 9.1 using Compiler Explorer, in x86-64, using -O3.
I have this code:
struct Base
Base()
double foo;
int bar;
;
struct Derived : public Base
int baz;
;
int main(int argc, char** argv)
return sizeof(Derived);
https://godbolt.org/z/OjSCZB
It correctly returns 16, as I would expect, 8 bytes for foo, and 4 bytes for bar and 4 bytes for baz. This works only because Derived inherits from Base and so it does not have to pad after bar due to Derived being a single type containing both Base and Derived elements.
I have two questions, as below:
First question
If I remove the explicit constructor of Base() , it starts returning 24, instead of 16. i.e. it adds padding after bar and baz.
https://godbolt.org/z/0gaN5h
I can't explain why having an explicit default constructor is any different to having an implicit default constructor.
Second question
If I then change struct to class for Base, it changes back to returning 16. I can not explain this either. Why would the access modifiers change the size of the structure?
https://godbolt.org/z/SCYKwL
c++ c++11 gcc
All of the below will be done on GCC 9.1 using Compiler Explorer, in x86-64, using -O3.
I have this code:
struct Base
Base()
double foo;
int bar;
;
struct Derived : public Base
int baz;
;
int main(int argc, char** argv)
return sizeof(Derived);
https://godbolt.org/z/OjSCZB
It correctly returns 16, as I would expect, 8 bytes for foo, and 4 bytes for bar and 4 bytes for baz. This works only because Derived inherits from Base and so it does not have to pad after bar due to Derived being a single type containing both Base and Derived elements.
I have two questions, as below:
First question
If I remove the explicit constructor of Base() , it starts returning 24, instead of 16. i.e. it adds padding after bar and baz.
https://godbolt.org/z/0gaN5h
I can't explain why having an explicit default constructor is any different to having an implicit default constructor.
Second question
If I then change struct to class for Base, it changes back to returning 16. I can not explain this either. Why would the access modifiers change the size of the structure?
https://godbolt.org/z/SCYKwL
c++ c++11 gcc
c++ c++11 gcc
edited Jul 20 at 12:18
Peter Mortensen
14.3k19 gold badges88 silver badges116 bronze badges
14.3k19 gold badges88 silver badges116 bronze badges
asked Jul 19 at 14:04
SalgarSalgar
6,3191 gold badge22 silver badges36 bronze badges
6,3191 gold badge22 silver badges36 bronze badges
3
Half a dupe of stackoverflow.com/q/47914612/560648. I don't know why changing the keyword introducing the base would make a difference though (given that there's no member re-ordering going on anyway so differing member access levels oughtn't come into it)
– Lightness Races in Orbit
Jul 19 at 14:08
Ah thanks! That answer the first question, but not the second
– Salgar
Jul 19 at 14:10
4
Re: "It correctly returns 16, as I would expect" -- by definition, the result ofsizeofis correct, regardless of what you expect.
– Pete Becker
Jul 19 at 14:11
Hmm yeah it's the access specifier; addpublic:.
– Lightness Races in Orbit
Jul 19 at 14:12
1
@LightnessRacesinOrbit not a bug. Aggregates can't have private members
– NathanOliver
Jul 19 at 14:13
|
show 1 more comment
3
Half a dupe of stackoverflow.com/q/47914612/560648. I don't know why changing the keyword introducing the base would make a difference though (given that there's no member re-ordering going on anyway so differing member access levels oughtn't come into it)
– Lightness Races in Orbit
Jul 19 at 14:08
Ah thanks! That answer the first question, but not the second
– Salgar
Jul 19 at 14:10
4
Re: "It correctly returns 16, as I would expect" -- by definition, the result ofsizeofis correct, regardless of what you expect.
– Pete Becker
Jul 19 at 14:11
Hmm yeah it's the access specifier; addpublic:.
– Lightness Races in Orbit
Jul 19 at 14:12
1
@LightnessRacesinOrbit not a bug. Aggregates can't have private members
– NathanOliver
Jul 19 at 14:13
3
3
Half a dupe of stackoverflow.com/q/47914612/560648. I don't know why changing the keyword introducing the base would make a difference though (given that there's no member re-ordering going on anyway so differing member access levels oughtn't come into it)
– Lightness Races in Orbit
Jul 19 at 14:08
Half a dupe of stackoverflow.com/q/47914612/560648. I don't know why changing the keyword introducing the base would make a difference though (given that there's no member re-ordering going on anyway so differing member access levels oughtn't come into it)
– Lightness Races in Orbit
Jul 19 at 14:08
Ah thanks! That answer the first question, but not the second
– Salgar
Jul 19 at 14:10
Ah thanks! That answer the first question, but not the second
– Salgar
Jul 19 at 14:10
4
4
Re: "It correctly returns 16, as I would expect" -- by definition, the result of
sizeof is correct, regardless of what you expect.– Pete Becker
Jul 19 at 14:11
Re: "It correctly returns 16, as I would expect" -- by definition, the result of
sizeof is correct, regardless of what you expect.– Pete Becker
Jul 19 at 14:11
Hmm yeah it's the access specifier; add
public:.– Lightness Races in Orbit
Jul 19 at 14:12
Hmm yeah it's the access specifier; add
public:.– Lightness Races in Orbit
Jul 19 at 14:12
1
1
@LightnessRacesinOrbit not a bug. Aggregates can't have private members
– NathanOliver
Jul 19 at 14:13
@LightnessRacesinOrbit not a bug. Aggregates can't have private members
– NathanOliver
Jul 19 at 14:13
|
show 1 more comment
2 Answers
2
active
oldest
votes
This all boils down to whether your type is an aggregate or not. With
struct Base
Base()
double foo;
int bar;
;
struct Derived : public Base
int baz;
;
Base is not an aggregate because of the constructor. When you remove the constructor, you make Base an aggregate which, per Adding a default constructor to a base class changes sizeof() a derived type, means gcc won't "optimize" for space and the derived object won't use the base's tail padding.
When you change the code to
class Base
double foo;
int bar;
;
struct Derived : public Base
int baz;
;
foo and bar are now private (becauses classes have private accessibility by default) which again means Base is no longer an aggregate as aggregates are not allowed to have private members. This means we are back to how the first case works.
1
And indeed addingpublic:changes it back to 24 again...
– Neil
Jul 20 at 10:00
add a comment |
With your Base class you will get 4 bytes of tail padding, and the same with the Derived class, that's why it should normally be 24 bytes total for the size of Derived.
It becomes 16 bytes, because your compiler is able to do tail padding reuse.
However tail padding reuse is problematic with POD types (all members public, defaulted constructor, etc...), because it breaks common assumptions a programmer would make. (So basically any sane compiler won't do tail padding reuse for pod types)
Let's pretend compilers would use the tail padding reuse for POD types:
struct Base
double foo;
int bar;
;
struct Derived : Base
int baz;
;
int main(int argc, char** argv)
// if your compiler would reuse the tail padding then the sizes would be:
// sizeof(Base) == 16
// sizeof(Derived) == 16
Derived d;
d.baz = 12;
// trying to zero *only* the members of the base class,
// but this would zero also baz from derived, not very intuitive
memset((Base*)&d, 0, sizeof(Base));
printf("%d", d.baz); // d.baz would now be 0!
When adding an explicit constructor to the Base class, or by changing the struct keywords to class, the Derived class doesn't satisfy the POD definition anymore and therefore tail padding reuse doesn't happen.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f57114179%2fdifference-between-class-and-struct-with-regards-to-padding-and-inheritance%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
This all boils down to whether your type is an aggregate or not. With
struct Base
Base()
double foo;
int bar;
;
struct Derived : public Base
int baz;
;
Base is not an aggregate because of the constructor. When you remove the constructor, you make Base an aggregate which, per Adding a default constructor to a base class changes sizeof() a derived type, means gcc won't "optimize" for space and the derived object won't use the base's tail padding.
When you change the code to
class Base
double foo;
int bar;
;
struct Derived : public Base
int baz;
;
foo and bar are now private (becauses classes have private accessibility by default) which again means Base is no longer an aggregate as aggregates are not allowed to have private members. This means we are back to how the first case works.
1
And indeed addingpublic:changes it back to 24 again...
– Neil
Jul 20 at 10:00
add a comment |
This all boils down to whether your type is an aggregate or not. With
struct Base
Base()
double foo;
int bar;
;
struct Derived : public Base
int baz;
;
Base is not an aggregate because of the constructor. When you remove the constructor, you make Base an aggregate which, per Adding a default constructor to a base class changes sizeof() a derived type, means gcc won't "optimize" for space and the derived object won't use the base's tail padding.
When you change the code to
class Base
double foo;
int bar;
;
struct Derived : public Base
int baz;
;
foo and bar are now private (becauses classes have private accessibility by default) which again means Base is no longer an aggregate as aggregates are not allowed to have private members. This means we are back to how the first case works.
1
And indeed addingpublic:changes it back to 24 again...
– Neil
Jul 20 at 10:00
add a comment |
This all boils down to whether your type is an aggregate or not. With
struct Base
Base()
double foo;
int bar;
;
struct Derived : public Base
int baz;
;
Base is not an aggregate because of the constructor. When you remove the constructor, you make Base an aggregate which, per Adding a default constructor to a base class changes sizeof() a derived type, means gcc won't "optimize" for space and the derived object won't use the base's tail padding.
When you change the code to
class Base
double foo;
int bar;
;
struct Derived : public Base
int baz;
;
foo and bar are now private (becauses classes have private accessibility by default) which again means Base is no longer an aggregate as aggregates are not allowed to have private members. This means we are back to how the first case works.
This all boils down to whether your type is an aggregate or not. With
struct Base
Base()
double foo;
int bar;
;
struct Derived : public Base
int baz;
;
Base is not an aggregate because of the constructor. When you remove the constructor, you make Base an aggregate which, per Adding a default constructor to a base class changes sizeof() a derived type, means gcc won't "optimize" for space and the derived object won't use the base's tail padding.
When you change the code to
class Base
double foo;
int bar;
;
struct Derived : public Base
int baz;
;
foo and bar are now private (becauses classes have private accessibility by default) which again means Base is no longer an aggregate as aggregates are not allowed to have private members. This means we are back to how the first case works.
edited Jul 19 at 14:28
answered Jul 19 at 14:21
NathanOliverNathanOliver
110k19 gold badges167 silver badges246 bronze badges
110k19 gold badges167 silver badges246 bronze badges
1
And indeed addingpublic:changes it back to 24 again...
– Neil
Jul 20 at 10:00
add a comment |
1
And indeed addingpublic:changes it back to 24 again...
– Neil
Jul 20 at 10:00
1
1
And indeed adding
public: changes it back to 24 again...– Neil
Jul 20 at 10:00
And indeed adding
public: changes it back to 24 again...– Neil
Jul 20 at 10:00
add a comment |
With your Base class you will get 4 bytes of tail padding, and the same with the Derived class, that's why it should normally be 24 bytes total for the size of Derived.
It becomes 16 bytes, because your compiler is able to do tail padding reuse.
However tail padding reuse is problematic with POD types (all members public, defaulted constructor, etc...), because it breaks common assumptions a programmer would make. (So basically any sane compiler won't do tail padding reuse for pod types)
Let's pretend compilers would use the tail padding reuse for POD types:
struct Base
double foo;
int bar;
;
struct Derived : Base
int baz;
;
int main(int argc, char** argv)
// if your compiler would reuse the tail padding then the sizes would be:
// sizeof(Base) == 16
// sizeof(Derived) == 16
Derived d;
d.baz = 12;
// trying to zero *only* the members of the base class,
// but this would zero also baz from derived, not very intuitive
memset((Base*)&d, 0, sizeof(Base));
printf("%d", d.baz); // d.baz would now be 0!
When adding an explicit constructor to the Base class, or by changing the struct keywords to class, the Derived class doesn't satisfy the POD definition anymore and therefore tail padding reuse doesn't happen.
add a comment |
With your Base class you will get 4 bytes of tail padding, and the same with the Derived class, that's why it should normally be 24 bytes total for the size of Derived.
It becomes 16 bytes, because your compiler is able to do tail padding reuse.
However tail padding reuse is problematic with POD types (all members public, defaulted constructor, etc...), because it breaks common assumptions a programmer would make. (So basically any sane compiler won't do tail padding reuse for pod types)
Let's pretend compilers would use the tail padding reuse for POD types:
struct Base
double foo;
int bar;
;
struct Derived : Base
int baz;
;
int main(int argc, char** argv)
// if your compiler would reuse the tail padding then the sizes would be:
// sizeof(Base) == 16
// sizeof(Derived) == 16
Derived d;
d.baz = 12;
// trying to zero *only* the members of the base class,
// but this would zero also baz from derived, not very intuitive
memset((Base*)&d, 0, sizeof(Base));
printf("%d", d.baz); // d.baz would now be 0!
When adding an explicit constructor to the Base class, or by changing the struct keywords to class, the Derived class doesn't satisfy the POD definition anymore and therefore tail padding reuse doesn't happen.
add a comment |
With your Base class you will get 4 bytes of tail padding, and the same with the Derived class, that's why it should normally be 24 bytes total for the size of Derived.
It becomes 16 bytes, because your compiler is able to do tail padding reuse.
However tail padding reuse is problematic with POD types (all members public, defaulted constructor, etc...), because it breaks common assumptions a programmer would make. (So basically any sane compiler won't do tail padding reuse for pod types)
Let's pretend compilers would use the tail padding reuse for POD types:
struct Base
double foo;
int bar;
;
struct Derived : Base
int baz;
;
int main(int argc, char** argv)
// if your compiler would reuse the tail padding then the sizes would be:
// sizeof(Base) == 16
// sizeof(Derived) == 16
Derived d;
d.baz = 12;
// trying to zero *only* the members of the base class,
// but this would zero also baz from derived, not very intuitive
memset((Base*)&d, 0, sizeof(Base));
printf("%d", d.baz); // d.baz would now be 0!
When adding an explicit constructor to the Base class, or by changing the struct keywords to class, the Derived class doesn't satisfy the POD definition anymore and therefore tail padding reuse doesn't happen.
With your Base class you will get 4 bytes of tail padding, and the same with the Derived class, that's why it should normally be 24 bytes total for the size of Derived.
It becomes 16 bytes, because your compiler is able to do tail padding reuse.
However tail padding reuse is problematic with POD types (all members public, defaulted constructor, etc...), because it breaks common assumptions a programmer would make. (So basically any sane compiler won't do tail padding reuse for pod types)
Let's pretend compilers would use the tail padding reuse for POD types:
struct Base
double foo;
int bar;
;
struct Derived : Base
int baz;
;
int main(int argc, char** argv)
// if your compiler would reuse the tail padding then the sizes would be:
// sizeof(Base) == 16
// sizeof(Derived) == 16
Derived d;
d.baz = 12;
// trying to zero *only* the members of the base class,
// but this would zero also baz from derived, not very intuitive
memset((Base*)&d, 0, sizeof(Base));
printf("%d", d.baz); // d.baz would now be 0!
When adding an explicit constructor to the Base class, or by changing the struct keywords to class, the Derived class doesn't satisfy the POD definition anymore and therefore tail padding reuse doesn't happen.
edited Jul 19 at 14:33
answered Jul 19 at 14:27
TurtlefightTurtlefight
1,1881 silver badge15 bronze badges
1,1881 silver badge15 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f57114179%2fdifference-between-class-and-struct-with-regards-to-padding-and-inheritance%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
Half a dupe of stackoverflow.com/q/47914612/560648. I don't know why changing the keyword introducing the base would make a difference though (given that there's no member re-ordering going on anyway so differing member access levels oughtn't come into it)
– Lightness Races in Orbit
Jul 19 at 14:08
Ah thanks! That answer the first question, but not the second
– Salgar
Jul 19 at 14:10
4
Re: "It correctly returns 16, as I would expect" -- by definition, the result of
sizeofis correct, regardless of what you expect.– Pete Becker
Jul 19 at 14:11
Hmm yeah it's the access specifier; add
public:.– Lightness Races in Orbit
Jul 19 at 14:12
1
@LightnessRacesinOrbit not a bug. Aggregates can't have private members
– NathanOliver
Jul 19 at 14:13