cs31 lecture 17

In one cpp file and use it issue in another file in

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ction prototype/implementation] } x Syntax for using a function from a given namespace: <name>::<function call> x Shortcut: using keyword using namespace <name>; x Alternative syntax for function implementation: <return type> <name>::<function name>([type1 arg1] [,type2 arg2])
 { <return [instructions] } [instructions] 70 Even more on namespaces x Namespaces can be nested namespace foo { namespace bar { namespace void blob()
; void } } foo::bar::blob()
 x Can split the definition of the namespace into multiple Can regions x Can go to the “root” namespace with ::myfuc()
 71 Potential issues x Multiple namespaces can define the same function x When using the using directive, ambiguity/unexpected When behavior may happen Example: std defines a function you have defined in your own Example: namespace namespace x Having multiple using directives 72 Using global variables in namespaces x Goal: define a variable associated with a namespace Example: store some internal state x Issue: how to declare a variable in one cpp file, and use it Issue: in another file? in For ex., cannot declare twice a function, we use function For prototype prototype Prototype for variable declaration: extern x Rule: a global varia...
View Full Document

This note was uploaded on 04/03/2014 for the course CS 31 taught by Professor Melkanoff during the Fall '00 term at UCLA.

Ask a homework question - tutors are online