   accessing parent class
  Is it possible to access a method or variable from a parent class?for example:class A {public:void af() {Here I want to access the parent class B's variable i} ;};class B {public:int i ;A avar ;void bf () {avar.af();}} ;[edited by - Emagen on July 31, 2003 4:37:58 PM]
    First you actually have to make class B the parent class of A, you have to derive A from B. Next the members (variables) and methods (functions) of B will be part of A. So you can automatically access them, and if a method is virtual it can be overridden (it can be different in the child than it is in the parent). I think your problem comes here:A avar ;void bf () {avar.af();the first line is good, what your doing is making a variable/member that is of type A, instead of type int like the i member in class B. As for the next two lines, I''m really not sure what your doing, it looks like you try to define then implement a function but don''t close the function with a } character.... Then you try to call it, inside the class???? I highly suggest you read up on classes because its fairly clear you misunderstand much of the syntax there.class B{int i;...virtual ~B();};class A: public B{} ;  Perhaps I should have rephrased that, I want to call the class that contains the instance of another class (without the use of inheritance).So in my exaple, what I am trying to do is have the class (A)call the class that declared it (B) to access (B)''s variables.  I hope that clears it up more.Thanks! ;    So you want A to access the members in B? If they members are of public scope just access them through the variable you created.class B{public:A avar;};B::B(){int Old = A.i;A.i = 5;}if the members you wish to access are not of public scope (private is defualt) then you''ll need to make accessor functions which are of public scope.class A{private:int i;public:inline int GetI() const { return i; }}Hope that helpsPat - Ex nihilo nihilus ;  Or another option is to make A a friend of B e.g.class A{public: void af() { }};class B{public:   friend class A;private:   int i;}; ;  I think you used the right terminology -In C++ ''child'' classes do not have implicit acces to the parent class.  You have to pass the child a pointer to the parent upon construction: struct Parent   {   Parent() : child(this)  //<- many compilers will complain about this   //It''s OK so-long-as ''this'' is not actually used by the ctor of child { }   struct Child { Child(Parent* p) : parent(p)    {//we just remember p for later//don''t call any methods here//or even set any properties    } Parent* parent; void SomeMethod()    {    parent->...    } } child;   };