Question about typedef template

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
WilsonHuang
Posts: 44
Joined: February 13th, 2019, 3:23 am

Question about typedef template

Post by WilsonHuang » June 8th, 2021, 11:00 am

Hi all,
I'm at 3D Programming Fundamentals Tutorial 16. At video 9:08 why we need double-colon before typedef Pipeline template? What does it do?

Code: Select all

	typedef ::Pipeline<GouraudPointEffect> Pipeline;
	typedef ::Pipeline<SolidColorEffect> LightIndicatorPipeline;
This is my first time to read statement like this.
Thanks.

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Question about typedef template

Post by albinopapa » June 14th, 2021, 12:35 pm

Double quotes qualify a variable with it's scope. In this case, it's requesting the Pipeline from the global scope ie the Pipeline<> template class which is aliased as Pipeline. The other alias is LightIndicatorPipeline made from Pipeline<SolidColorEffect>. The compiler might get confused and try using the alias Pipeline which would work since it's not a template.

Say you had a global/free function called DoUpdate() and a DoUpdate() member function. If you are in object.SomeFunction() and call DoUpdate() by itself then it would call object.DoUpdate(). However, if you call ::DoUpdate() you call the global/free function.

For some reason some people like to qualify all their global function calls or what have you with double quotes, but in this case it's necessary to distinguish between a locally defined alias and the globally defined Pipeline<> template class.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

WilsonHuang
Posts: 44
Joined: February 13th, 2019, 3:23 am

Re: Question about typedef template

Post by WilsonHuang » June 16th, 2021, 2:42 am

albinopapa wrote:
June 14th, 2021, 12:35 pm
Double quotes qualify a variable with it's scope. In this case, it's requesting the Pipeline from the global scope ie the Pipeline<> template class which is aliased as Pipeline. The other alias is LightIndicatorPipeline made from Pipeline<SolidColorEffect>. The compiler might get confused and try using the alias Pipeline which would work since it's not a template.

Say you had a global/free function called DoUpdate() and a DoUpdate() member function. If you are in object.SomeFunction() and call DoUpdate() by itself then it would call object.DoUpdate(). However, if you call ::DoUpdate() you call the global/free function.

For some reason some people like to qualify all their global function calls or what have you with double quotes, but in this case it's necessary to distinguish between a locally defined alias and the globally defined Pipeline<> template class.
Thanks, now I understand, because first line define Pipeline<GouraudPointEffect> as Pipeline. The second line Pipeline<SolidColorEffect> LightIndicatorPipeline will use first line expression. So we need to use double colon to call the global one. Thanks for explanation.

Post Reply