//  Scope of constant 


// typedef and const has internal linkage by default.
// file1:
    // bad practice...
    typedef int my_type;
    const int ci = 10;

// file2:
    // bad practice...
    typedef double my_type;
    const int ci = 20;



// but const can be declared external
// file1:
    extern const int ci = 10;

// file2:
    extern const int ci;



//
// Constant class members
//
// file: list.h

#ifndef LIST_H
#define LIST_H

#include <iostream>

class list
{
public:
         list();
         ~list();

    list *remove();
    void  append(list *lp);
    void  insert(list *lp);
    list *get_next() const { return next; }
    list *get_prev() const { return prev; }

    void print( std::ostream& os) const;

    static int get_nid() { return nid; }
private:
    const int  id;
          list *next;
          list *prev;

    static int nid;

    list( const list &rhs);
    list operator=( const list *rhs);
};

std::ostream& operator<<( std::ostream&, const list&);

#endif /* LIST_H */



////////////////////////////////////////////////////////



// file: list.cpp

#include <iostream>
#include "list.h"

using namespace std;

int list::nid = 0;

list::list() : id(nid), prev(0), next(0)
{
    ++nid;
}
// ...


//  Static constants in class 


// file: a.h
class X
{
    static const int  c1 = 7;    // ok, but remember definition
    static       int  i2 = 8;    // error: not const
    const        int  c3 = 9;    // error: not static
    static const int  c4 = f(2); // error: initializer not const
    static const float f = 3.14; // error: not integral 
};

const int X::c1;  // do not repeat initializer here...