• 0

Question about Template C++


Question

This will compile.

<pre>



namespace tmp{

long double pi = 3.14159265358979323846; //to 20 decimal places.

}



template <class T>

T rad(T degrees){

T pi = (T) tmp::pi; //converts pi to necessary type for math below. 

return (degrees * pi / 180 );

};



template <class T>

T deg(T radians){

T pi = (T) tmp::pi; //converts pi to necessary type for math below.

return (degrees * 180 / pi);

};</pre>

But if I remove the second "template " it won't. Is it because the template is tied to a single function or class?

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.