File: intro.yo

package info (click to toggle)
c%2B%2B-annotations 13.02.02-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,576 kB
  • sloc: cpp: 25,297; makefile: 1,523; ansic: 165; sh: 126; perl: 90; fortran: 27
file content (16 lines) | stat: -rw-r--r-- 1,024 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Imagine a math teacher who wants to develop an interactive math program. For
this program functions like tt(cos, sin, tan) etc. are to be used
accepting arguments in degrees rather than arguments in
radians. Unfortunately, the function name tt(cos) is already in use, and that
function accepts radians as its arguments, rather than degrees.

Problems like these are usually solved by defining another name, e.g., the
function name tt(cosDegrees) is defined. bf(C++) offers an alternative
solution through hi(namespace)em(namespaces). Namespaces can be considered as
areas or regions in the code in which identifiers may be defined. Identifiers
defined in a namespace normally won't conflict with names already defined
elsewhere (i.e., outside of their namespaces). So, a function tt(cos)
(expecting angles in degrees) could be defined in a namespace
tt(Degrees). When calling tt(cos) from within tt(Degrees) you would call the
tt(cos) function expecting degrees, rather than the standard tt(cos) function
expecting radians.