Aggregation

Need help with aggregation of classes. Suppose class Passenger is aggregated to class Bus. Then how to overload = operator in class Bus.

1
2
3
4
5
6
7
8
9
10
11
12
  class Bus
{
  Passenger *p;
  public:
  Bus operator = ( const Bus & obj )
  {
    p = obj.p;
  }
}; 

//is it right??
1
2
3
4
5
6
7
8
9
10
class passenger { /* ... */ } ; // CopyAssignable

class bus
{
     // aggregated: a bus owns its passengers
     std::vector<passenger> passengers ; 
     
     // there is no need to declare this.  (vectors are CopyAssignable)
     // public: bus& operator= ( const bus& that ) = default ;
};

See: http://www.mochima.com/tutorials/vectors.html
Topic archived. No new replies allowed.