Home

On 2007-08-21 17:26, Tian.Xiao.2007@gmail.com wrote:
> Dear All,
>
> Assume I have a Car class, which include some parts, i.e,
>
> class Engine;
> class Transmission;
> class Car
> {
> private:
> Engine *m_engine;
> Transmission *m_transmission;
> ...
> }
>
> Assume engine and transmission in a car must have the same maker, for
> example: Ford car can have Ford engine and Ford transmission, how to
> implement this constraint in the class design?

By checking when you set the engine of the Car:

void setEngine(Engine* e)
{
if (e->type != this->type)
{
// Do something, like throw an exception
}
m_engine = e;
}

--
Erik Wikstrm

previous
next

Re: How to allocate a static class attribute in c++?
Re: Why Java Fail and C++ rise
Re: Move files/directories to Recycle Bin using standard Python libs
Re: Does shuffle() produce uniform result ?
Re: How to detect read or write access to a user defined array?
strony internetowe chojnice
tanie pozycjonowanie
kolektory słoneczne Łódź
mlmfrustrationsabolished.com
news