Click here to Skip to main content
15,943,148 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

I have 3 classes A,B,C

I want class C variable to be access to class A but not to class B. How can be achieve that without inheritance?

Regarding Serialization
I have 3 xml object which is already serialize now I want only 2 object to deserialize how can it be possible?


You can't, unless they are in different assemblies.
You have five options for accessibility:

private - within the same class only
protected internal - within the containing class, and classes derived from the containing class only
internal - within the same assembly
protected - within the class, and derived classes only
public - accessable anywhere, but anyone

There is no provision for limiting it to specific class names.
Share this answer
XamBEE 9-Mar-16 4:44am    
If i have 2 classes(Class A, Class B). I want to access Class A variable into class B.
int TestVariable= 21;

cout<<ObjClassB.TestVariable<<endl; //want to display/update public variable of classA here.
I know this is wrong but dont know how to do this??
OriginalGriff 9-Mar-16 4:54am    
First off, this isn't relevant to this question - the original is C#, while that is C++ code.
The two look similar, but are completely different languages!
Second, this should be your own question, instead of "tagged on" to a three year old answer. You can't guarantee that a member from three years ago is still active here, and if they aren't, you just never get a response!
Thirdly, TestVariable is an instance variable of ClassA - so you need an instance of Class A in ClassB in order to access it!.
Think of TextVariable as the glove box of a car: you need to have a specific instance of a car in order to open the right glovebox. If you put your mobile in the glove box of your car, then you won't find it by opening the glove box on my car! :laugh:
Make class C variables internal (access modifier) and place class A and C in one dll and Class B in other dll.

Can you place you can use the `internal` access modifier which will make this class/variables accessible to the
other classes in the same assembly, but not accessible outside the assembly.

For serialization you can use ISerializable Interface to write custom serialization logic.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900