I have some code using itk libraries, and I would like to display itk built version when calling them.
//get itk version
std::cout << whichItk.GetITKBuildVersion() << std::endl;
which is not working as the constructor is “protected” so I get the error:
‘itk::Version::Version’: cannot access protected member declared in class ‘itk::Version’
I guess there is another solution than declaring all itk class as friend class of mine.
I must do something wrong when calling the version class.
@phcerdan Does this test help?
I also remember Brad or Hans having contributed with a quantitative test using GTest for testing the ITK version, but am unable to find it now.
I succed by doing:
const char * itkVersion = itk::Version::GetITKVersion();
std::cout << "itk version: " << itkVersion << std::endl;
this one works as well:
itk::Version::Pointer version = itk::Version::New();
std::cout << version->GetITKVersion() << std::endl;
but I am not sure why it works. it’s not calling the constructor ?
why there is no “can’t access protected memeber class” when calling this way ?
(I guess it’s more a c++ than a itk function, but I don’t understand why I don’t get the error when doing this way)
New() is a member function of
itk::Version class, so it can access all its members, including protected and private ones.
And you can access
New() because it is public.
and new is inherited from Object i guess
ok thanks for the explanation.
(and sorry for the dumb question …)
New is a macro, defined in itkMacro.h and used by pretty much every descendant of
Object, including Version. Thus
New is not an inherited member, but rather direct member defined in
Yes. That macro creates a few member functions, including
thanks a lot for all explanations.