The Open Source Swiss Army Knife

/code/cPP/
/code/cPP/ + sub-categories
http://www.sirfsup.com/
web directory content
    
      

Not logged in
Chat Register Login
return to:  http:/www.sirfsup.com      /code   /cPP 
Permalink: definitions.html
Title: add
article options : please login   |  print view

  1. constant initialization
  2. struct initialization
  3. advanced keywords
  4. functors
  5. class_impl

constant initialization

class data_list {
public:
const int data_size; //number of items in list
data_list() : data_size(1024) {
// rest of constructor definition
}

struct initialization

the name following struct and before the delcaration is what the structure of that name looks like; the name following the struct definition is an alias/synonym for that structure, like in using a typedef.

advanced keywords

http://www.csse.uwa.edu.au/programming/c++.tutorial/glossary/
  1. typename
    http://www.codeguru.com/cpp/tic/tic0201.shtml
  2. explicit
    example: class Buffer {
    public:
    /// Instantiate on filename.
    explicit Buffer(const char* filename);
    /// Instantiate on open input fstream.
    explicit Buffer(std::istream* is);
    /// Instantiate on existing buffer.
    explicit Buffer(const char* buffer, unsigned long size);
    /// Instantiate on subsection of existing buffer
    explicit Buffer(const Buffer& buf, unsigned long start, unsigned long end);
    MEANING: Prevents an object being intialized using a statement of the form 'X x=1', where x is an object of class X" source=http://www.kevinboone.com/ctut_keywords.html

    but that applies to objects, not functions; hence it is used in the constructor (?)

  3. extern
    MEANING: Indicates that something used in one program module (file) is defined in a different program module.
    see var_scope.htm
  4. mutable
    MEANING: Indicates that a data element in an object can be changed, even by operations which claim not to change data
  5. static
    MEANING: A variable that is part of a class, yet is not part of an object of that class, is called static member. There is exactly one copy of a static member instead of one copy per object, as for ordinary non-static members. Similarly, a function that needs access to members of a class, yet does not need to be invoked for a particular object, is called a static member function.
    (source: http://www.sci.brooklyn.cuny.edu/~cis22/cvscpp/static/
    session.cpp:20: error: `session& operator=(const session&)' must be a nonstatic
       member function
    session.cpp:20: error: `session& operator=(const session&)' must take exactly
       two arguments
    
    ----------------
                                                                                                                                                             
    (line 20)
    session & operator = (const session & other) {
      sid = other.sid;
      dataMap = other.dataMap;
      touched = other.touched;
      return *this;
    }
    (from header -- def)
     session & operator = (const session &); // assignment operator
    ----------- solution -----------------------
    use session & session::operator = (const session & other)
    

functors

http://logic.philosophy.ox.ac.uk/tutorial2/Tut2-01.htm

"Fast jeder C Programmierer hat sich schon mit Zeigern auf Funktionen herumschlagen müssen. Diese kommen immer dann zur Anwendung, wenn eine Funktion als Parameter an eine andere Funktion übergeben werden soll. Beispiele sind die Standard C Library Funktionen bsearch und qsort. "http://cplus.kompf.de/artikel/functors.html

Ein Functor ist ein Objekt, welches operator() definiert.

Functors are function pointers.

Interessant ist auch die Verwendung von vordefinierten Functors als »Callback« Funktionen in den *_if Algorithmen der STL, wie find_if, count_if, replace_if oder remove_if. (see the corresponding names in libptp)

class_impl

For example, Parser constructor really calls parser_impl(); Parser::Parser(const char* filename)
{
imp = new Parser_Impl(filename);
}


Leave a Reply
Your Name:     anonymous
Your Email:
Website:  
Comments:

The author will be notified of your reply.
return to top