By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,918 Members | 2,258 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,918 IT Pros & Developers. It's quick & easy.

union in C++

P: 9
I want to know wether the visibility mode like private,public & protected exists for union in C++? If exists how memory allocation takes place? Can a union in C++ keeps a member function? Does a this pointer exists for a union in C++?
Jun 2 '07 #1
Share this Question
Share on Google+
6 Replies


AdrianH
Expert 100+
P: 1,251
I want to know wether the visibility mode like private,public & protected exists for union in C++? If exists how memory allocation takes place? Can a union in C++ keeps a member function? Does a this pointer exists for a union in C++?
The answer is yes to all but the 2nd and to that the answer is that it does it just like a class/struct.

I'd say try it out.


Adrian
Jun 2 '07 #2

weaknessforcats
Expert Mod 5K+
P: 9,197
Can a union in C++ keeps a member function? Does a this pointer exists for a union in C++?
Yes, you can have a member function and yes there is a this pointer. However, it's up to you to remember what's in the union. Only one data member at a time can exist.

Rarely do you see this in C++. A class hierarchy is used instead with the derived classes containing the various data members.
Jun 2 '07 #3

AdrianH
Expert 100+
P: 1,251
Yes, you can have a member function and yes there is a this pointer. However, it's up to you to remember what's in the union. Only one data member at a time can exist.

Rarely do you see this in C++. A class hierarchy is used instead with the derived classes containing the various data members.
But its lots of fun. ;)


Adrian
Jun 2 '07 #4

Savage
Expert 100+
P: 1,764
But its lots of fun. ;)


Adrian
This is subjective statement

Savage
Jun 2 '07 #5

AdrianH
Expert 100+
P: 1,251
This is subjective statement

Savage
One word Savage, sarcasm. ;)


Adrian
Jun 2 '07 #6

Savage
Expert 100+
P: 1,764
One word Savage, sarcasm. ;)


Adrian
:)

Savage
Jun 3 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.