Table of Contents

Convenção de Programação

Recomendações para programação em C++.
Baseado em “The Elements of C++ Style - T. Misfeldt, G. Bumgardner, A. Gray

Namespace

Exemplo

namespace TerraLib
{
  ....
  std::string myString = getName();
  ....
}

Preprocessador

Example

#ifndef TE_CONNECTION_POOL_H
#define TE_CONNECTION_POOL_H
....
static const float TeMaxFloat = 3.4e37;
....
#endif // end TE_CONNECTION_POOL_H

Declarações

Example

typedef std::pair<TeLine, double> TeLineLength;
typedef std::vector<lineLength> TeLineSizes;
 
enum TeSelectionMode
{
  TeSelectionModeDefault,	  //!< default selection
  TeSelectionModeTePointed,	  //!< object pointed
  TeSelectionModeTeQueried,	  //!< object queried
  TeSelectionModeTePointedQueried //!< object pointed and queried
}

Escopo

Example

for (int i = 0; i < 10; i++)

Funções e Métodos

Classes

Membros de Classes

Operadores

Templates

Exemplo

// Example of bad macro
#define MAX(a,b) ( ((a) > (b)) ? (a) : (b) )
 
// Use template instead
template<class T>
inline T max (const T& a, const T& b)
{
  return (a > b) ? a : b/
}

Segurança, Cast e Conversões de Tipos

Inicialização e Construção

Declarações e Expressões

Fluxo de Controle

Manipulação de Erros e Exceções

Eficiência