Page 1 of 1

Question about typedef template

Posted: June 8th, 2021, 11:00 am
by WilsonHuang
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.

Re: Question about typedef template

Posted: June 14th, 2021, 12:35 pm
by albinopapa
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.

Re: Question about typedef template

Posted: June 16th, 2021, 2:42 am
by WilsonHuang
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.