Science Fair Projects Ideas - Namespace mechanism

All Science Fair Projects

      

Science Fair Project Encyclopedia for Schools!

  Search    Browse    Forum  Coach    Links    Editor    Help    Tell-a-Friend    Encyclopedia    Dictionary     

Science Fair Project Encyclopedia

For information on any area of science that interests you,
enter a keyword (eg. scientific method, molecule, cloud, carbohydrate etc.).
Or else, you can start by choosing any of the categories below.

Namespace mechanism

A namespace, in the context of computer programming, refers to the concept of the name of a construct, variable or constant, and within which scopes it is visible.

Example:

class Chicken () : public Bird {
  public:
    int   nWings = 2;
    int   nLegs = 2;
    int   bFlight = FALSE;
    void  Cluck () {}
}

class Hen () : public Chicken {
  public:
    void  LayEggs () {}
}

class Cock () : public Chicken {
  public:
    void  Cockadoodledoo () {}
}

void main () {
    Chicken* pClucker;   // Chicken pointers can be used with Chickens, Hens and Cocks
    pClucker = new Hen;  // create a Hen

// The functions Cockadoodledoo (), Cluck (), and LayEggs () are not available at this scope.  
// They are within a different namespace.

    Cluck ();    // This function call will fail, there is no Cluck () in this namespace.
    LayEggs ();  // This function call will fail, there is no LayEggs () in this namespace.

// These function calls will succeed, because they are being called within a different namespace.

    pClucker -> Cluck ();    // you can call a Chicken function through a Chicken pointer
    pClucker -> LayEggs ();  // you can call a Hen function through a Chicken pointer

// If we define Cluck () outside the context of a Chicken...

    void Cluck () {}

// ...this function call will now succeed.

    Cluck ();

// Note that these two function calls...

    pClucker -> Cluck ();    
    Cluck ();

// Now do two different things, because they are being called from different namespaces; 
// the Chicken namespace, and the main () namespace.

}

(This example may have confused the concept of "scope" with the concept of "namespace". Please adjust accordingly.)

Last updated: 10-25-2005 03:23:20
03-10-2013 05:06:04
The contents of this article is licensed from www.wikipedia.org under the GNU Free Documentation License. Click here to see the transparent copy and copyright details
Science kits, science lessons, science toys, maths toys, hobby kits, science games and books - these are some of many products that can help give your kid an edge in their science fair projects, and develop a tremendous interest in the study of science. When shopping for a science kit or other supplies, make sure that you carefully review the features and quality of the products. Compare prices by going to several online stores. Read product reviews online or refer to magazines.

Start by looking for your science kit review or science toy review. Compare prices but remember, Price $ is not everything. Quality does matter.
Science Fair Coach
What do science fair judges look out for?
ScienceHound
Science Fair Projects for students of all ages
All Science Fair Projects.com Site
All Science Fair Projects Homepage
Search | Browse | Links | From-our-Editor | Books | Help | Contact | Privacy | Disclaimer | Copyright Notice