[Insight-developers] GetMacro vs GetConstMacro
Luis Ibanez
ibanez@cs.unc.edu
Tue, 20 Feb 2001 12:09:18 -0500
Hi,
itkGetMacro( name, type ) generates:
virtual type GetName(void ) {
return m_Name;
}
itkGetConstMacro(name, type ) generates:
virtual const type GetName( void ) const {
return m_Name;
}
The second is maybe the one that we should
use most of the time, because in general a Get()
operation doesn't modify the object.
But, some compiles complain when they find
const int GetName()... because 'const'
is meaninless when passing by value.
-----
Most of the time GetConstMacro is used to get
access to a member variable in the class. Could
we use a pass by reference instead of passing
by value in GetConstMacro ?
like:
itkGetConstMacro( name, type )
virtual const type & GetName(void ) const {
return m_Name;
}
----
This is important for enforcing constness in other places.
for example, now it is not possible to call :
GetProgress()
GetNumberOfThreads();
GetNumberOfRequiredInputs();
GetNumberOfRequiredOutput();
on a const itkProcessObject (that means: in any const filter)
-----------
Thanks
Luis