ITK Lecture 2A brief C++ review

Namespaces

Namespaces solve the problem of classes that have the same name
E.g., ITK contains an Array class, perhaps your favorite add-on toolkit does too
You can avoid conflicts by creating your own namespace around code namespace itk { code }
Within a given namespace, you refer to other classes in the same namespace by their name only, e.g. inside the itk namespace Array means “use the ITK array”
Outside of the namespace, you use the itk:: prefix, e.g. itk::Array
Only code which is part of the toolkit should be inside the itk namespace
At minimum, you’re always in the global namespace
Note that code within the itk namespace should refer to code outside of the namespace explicitly
E.g. use std::cout instead of cout

Object-oriented programming

Identify functional units in your design
Write classes to implement these functional units
Separate functionality as much as possible to promote code re-use

class membership
Classes have member variables and methods
ITK names class member variables with the “m_” prefix, as in “m_VariableName”
Class members are 1 of 3 types
Public
Private
Protected

public membership
Everyone can access the member
The rest of the world
The class itself
Child classes
You should avoid making member variables public, in order to prevent undesired modification

private memership
Only the class itself can access the member
It’s not visible to the rest of the world
Child classes can’t access it either

protected
The middle ground between public and private
The outside world can’t access it… but derived classes can

ITK membership
In ITK, member variables are almost always private
There are public accessor functions that allow the rest of the world to get and set the value of the private member
This ensures that the class knows when the value of a variable changes

Cours gratuitTélécharger le cours complet

Télécharger aussi :

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *