   subclass access to parentclass
  ive got a class structure like this...class A{   A()   {B Loader;Loader.LoadData;   }   class B : FileParser   { LoadData();   }}i would like that objects with the type B should have access to variables in A... im not sure this is the best way to do it...the class B is just a specialized Loader class for A which is derived from a fileparser and specifies how data should be loaded using the parser... and id like this object to die once all the data is loaded into A...as it is now i have to redefine all the elements in B and then copy them to A once ive loaded... which is not good... i could use shared pointers...but thats an ugly solution...   
  You can't.There are ways to hack such functionality, but not for your case. Pass the reference to loader data in constructor to B.   ;  Unless I've missed something the only way I know is to pass a reference to A to B when you instantiate the class. Class B, unless you dispose the object will live as long as A does. It sounds like you might be better off making Class B a method of A and returning the loaded data instead.//passing a reference to the parent to the childclass A{B b = new B(this);public int Foo;}class B{A a;B(A a){this.a = a;}void DoSomething(){//now you can access any public member of Athis.a.Foo += 1;}}//using class B as a method instead of a classclass A{string myData;A(){myData = this.LoadData("myfilename");}string LoadData(string filename){FileParser fileParser = new FileParser();string data = fileParser.LoadFileData(filename);return data;}}   ;Original post by keshtathIt sounds like you might be better off making Class B a method of A and returning the loaded data instead.well the problem with that is that i have to create a VERY large function... with all the loading functionality "ALLLoadData(string filename)"... instead of being able to split up the loading functions into several smaller ones that are actually readable...;  You could include all those helper functions into class A, but that would cause clutter.   ;  What you can, but should not do: instead of a local object in A's constructor, make B a member of class A. Then, knowing the offset of B in A (in bytes) you could, in B's member functions, cast "this" into byte*, substract "offset" and cast the result into A*Of course, if:- B's offset in A changes because you add other members- B's offset changes because A gets a virtual function and you don't take the vfptr into account- B is ever used outside of A- Many (many) other reasonsYour program will go nuclear.(And B won't die when loading has finished, so, disregard this post)[lol];Original post by Dragon_StrikeQuote:Original post by keshtathIt sounds like you might be better off making Class B a method of A and returning the loaded data instead.well the problem with that is that i have to create a VERY large function... with all the loading functionality "ALLLoadData(string filename)"... instead of being able to split up the loading functions into several smaller ones that are actually readable...Splitting functionality into classes only for the sake of readablity isnt always the best idea. Proper formatting, commenting, and design should should allow even a large class to remain servicable. Also keep in mind you can use regions in c# allowing you to collapse large sections of code allowing the even the largest classes to become managable.For example:#region File Description//-----------------------------------------------------------------------------// AnimatedSprite.cs//// Microsoft XNA Community Game Platform// Copyright (C) Microsoft Corporation. All rights reserved.//-----------------------------------------------------------------------------#endregionSo unless someone else knows a trick I dont, you have 3 basic options.1: Put the functionality of B into Class A (making a single big class)2: Split up the two classes and pass a reference to the parent class. (see my example in my first post)3: Redesign your classes so that they can be made a more manageble size.