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 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 …
Jump to PostI still don't know exactly what you mean. Are you talking about the order in which a program executes the lines, for instance
char* a = new char[25]; // something here char* b = new char[25]; // more stuff here
Or are you asking if the memory …
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,265 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.