how is this considered hiding methods?

Gor Gyolchanyan gor.f.gyolchanyan at gmail.com
Sat Sep 22 01:06:51 PDT 2012


On Saturday, 22 September 2012 at 07:48:02 UTC, Gor Gyolchanyan 
wrote:
> Can someone please tell me why the following code gives these 
> errors?
>
> Error: class main.BirdZoo use of main.VertebrateZoo.take(Animal 
> animal_) hidden by BirdZoo is deprecated
>
> Error: class main.ParrotZoo use of 
> main.VertebrateZoo.take(Animal animal_) hidden by ParrotZoo is 
> deprecated
>
> /// The code:
>
> 	class Animal { }
> 	class Vertebrate { }
> 	class Bird: Animal { }
> 	class Parrot: Bird { }
> 	
> 	class VertebrateZoo
> 	{
> 		void take(Animal animal_)
> 		{
> 			if(auto vertebrate = cast(Vertebrate)animal_)
> 				take(vertebrate);
> 		}
> 		
> 		abstract void take(Vertebrate vertebrate_);
> 	}
> 	
> 	class BirdZoo: VertebrateZoo
> 	{
> 		override void take(Vertebrate vertebrate_)
> 		{
> 			if(auto bird = cast(Bird)vertebrate_)
> 				take(bird);
> 		}
> 		
> 		abstract void take(Bird bird_);
> 	}
> 	
> 	class ParrotZoo: BirdZoo
> 	{
> 		override void take(Bird bird_)
> 		{
> 			if(auto parrot = cast(Parrot)bird_)
> 				take(parrot);
> 		}
> 		
> 		abstract void take(Parrot parrot_);
> 	}
> 	

I figured it out:

	class BirdZoo: VertebrateZoo
	{
		alias VertebrateZoo.take take;

		override void take(Vertebrate vertebrate_)
		{
			if(auto bird = cast(Bird)vertebrate_)
				take(bird);
		}
		
		abstract void take(Bird bird_);
	}
	
	class ParrotZoo: BirdZoo
	{
		alias BirdZoo.take take;

		override void take(Bird bird_)
		{
			if(auto parrot = cast(Parrot)bird_)
				take(parrot);
		}
		
		abstract void take(Parrot parrot_);
	}



More information about the Digitalmars-d-learn mailing list