Cpp

From Chessprogramming wiki
Jump to: navigation, search

Home * Programming * Languages * C++

C++,
a pragmatical, object oriented, general-purpose programming language, initially an extension of C and designed and implemented in 1979 by Bjarne Stroustrup from Bell Laboratories. C++ is pragmatical because one may write in "usual" C-style, using the C standard library (printf, strcpy, ...), except perhaps using C++ comments and references up and then (instead of pointer). On the other hand C++ allows to design classes and interfaces (pure virtual classes) in a more object oriented manner. There are lots of free and commercial class libraries for arithmetics, database related stuff, portable and proprietary window management and whatever else. Many chess engines are written in C++, varying from using pure C-style, up to extensive use of object oriented stuff and templates as well as C++11 or C++17 features.

C Extensions

References

Exception Handling

Classes

Classes as declaration for objects are more or less C-Structures. None static functions may be declared inside the scope of a class. Those functions, called member functions, have an implicit parameter called "this", a pointer to this structure, allocated either inside the data segment or bss as static or global, via "new" (malloc) on the heap or as automatic object (variable) on the stack.

Data Definition

Member Functions

Modifiers

Pointer to Member Functions

For instance an array of member function pointers of a class CNode, which is indexed by arbitrary pieces code - as switch-case replacement via indirect call/jump. The special atomic C++ operator '->*' is used to call the indexed member-functions:

class CNode {
  U64 AssertAttack (EnumSquare sq) const;
  U64 wPawnAttacks (EnumSquare sq) const;
  U64 bPawnAttacks (EnumSquare sq) const;
  U64 knightAttacks(EnumSquare sq) const;
  U64 kingAttacks  (EnumSquare sq) const;
  U64 bishopAttacks(EnumSquare sq) const;
  U64 rookAttacks  (EnumSquare sq) const;
  U64 queenAttacks (EnumSquare sq) const;
  ...
  typedef U64 (CNode::*AttackPtrType)(EnumSquare sq) const;
  static AttackPtrType m_scPieceAtta[14];
  ...

  U64 getAttack(EnumSquare sq, EnumPiece piece) const {return (this->*m_scPieceAtta[piece])(sq);}
};

CNode::AttackPtrType CNode::m_scPieceAtta[14] =
{
  AssertAttack,
  AssertAttack,
  wPawnAttacks,
  bPawnAttacks ,
  bishopAttacks,
  bishopAttacks,
  knightAttacks,
  knightAttacks,
  rookAttacks,
  rookAttacks,
  kingAttacks,
  kingAttacks,
  queenAttacks,
  queenAttacks
};

Inheritance

Function Overloading

Operator Overloading

Late Binding

Abstract Classes

Pure Abstract Classes

Multiple Inheritance

Templates

Anonymous Functions

Smart Pointer

Class Design of a Chess Engine

main article Class Design of a Chess Engine

C++ Compiler

Libraries

NIH Class Library — Software Preservation Group, The Computer History Museum [1]

See also

C++ Publications

1985 ...

1990 ...

1995 ...

2000 ...

2005 ...

2010 ...

Forum Posts

1997 ...

Re: Search Degredation w/ C++ by Amir Ban, rgcc, June 17, 1997
Re: object oriented chess programming by Dave Fotland, rgcc, January 06, 1998

2000 ...

2005 ...

2010 ...

2015 ...

2020 ...

Re: C++ code for board[8][8] representation by Rein Halbersma, CCC, March 08, 2021 [6]

External Links

Calling conventions for different C++ compilers and operating systems (pdf) by Agner Fog

References

Up one Level