[Insight-developers] GetMacro vs GetConstMacro
Miller, James V (CRD)
millerjv@crd.ge.com
Tue, 20 Feb 2001 13:13:19 -0500
I have been struggling with this as well. I think the solution is probably to have more macros. I
think of it as a matrix of options:
1) Do I want to return a copy or a reference to a item?
2) Do I want the user to be able to modify the item returned, is item const?
3) Do I want the user to be able call the method on a const object?
There is a forth option of calling on a const object AND allowing the user to modify the return value
but that case should be avoided. So to me it seems as though there should be 3 macros.
-----Original Message-----
From: Luis Ibanez [mailto:ibanez@cs.unc.edu]
Sent: Tuesday, February 20, 2001 12:09 PM
To: insight-developers@public.kitware.com
Subject: [Insight-developers] GetMacro vs GetConstMacro
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
_______________________________________________
Insight-developers mailing list
Insight-developers@public.kitware.com
http://public.kitware.com/mailman/listinfo/insight-developers