Aside from access specifiers (private, public, protected), what differentiates structures and unions from classes in C++? I have been told that in C++, classes and their associated components are instantiated in memory in pretty much random order, but structs and unions are instantiated in a fixed order? Is this true? Where can I find this information?
monstro
0
Newbie Poster
Recommended Answers
Jump to PostThere is no difference between structures and c++ classes other than default access. Unions are the same as they are in C -- all members of a union occupy the same memory location.
>>classes and their associated components are instantiated in memory in pretty much random order, but structs …
Jump to PostBoth structure and class objects should be allocated in the order in which they are declared. If allocated dynamically then the memory will be in some memory that is unknown to the program (the memory allocation functions will of course know).
I agree with Dragon, even if a random memory …
Jump to Post>>This is a code wich proves this point
Your code proves nothing.>>the pointers in the class should occupy memory in the order they are declared
Don't count on it. 1) never use malloc in c++. 2) whether malloc or new is used there is no guarentee how the …
All 11 Replies
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
Prabakar
77
Posting Whiz
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
Prabakar
77
Posting Whiz
monstro
0
Newbie Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
Salem
5,138
Posting Sage
Duoas
1,025
Postaholic
Featured Poster
vijayan121
1,152
Posting Virtuoso
monstro
0
Newbie Poster
Duoas
1,025
Postaholic
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.