class Brain
def man; :man; end
end
class Man
attr :brain
def initialize; @brain = Brain.new; end
end
m = Man.new()
puts m.brain # mans brain
puts m.brain.man # self
 
                
        
     
                
        
    struct Brain{
   struct Man& man;
   Brain( Man& m ) : man(m) {}
   void do_brain_stuff(){}
};
struct Man{
   Brain brain;
   Man() : brain( *this ) {}
   void do_man_stuff(){}
};
int main(){
   Man m;
   m.brain.do_brain_stuff();
   m.brain.man.do_man_stuff();
   return 0;
}
        
         
                
        
     
                
        
     
                
        
     
                
        
    
I am wondering if someone could display a very simple example of using references vs. pointers for object composition. I am still a little confused.
Here's an example of what I'm describing in Ruby for brevities sake:
I realize in ANSI C you would just use pointers, but I am choosing to use references since my embedded objects will be permanent. I also prefer the dot ( . ) operator as well vs. the (->) pointer notation.
Would someone be willing to provide a concise example of the above Ruby in C++?