I have some code using itk libraries, and I would like to display itk built version when calling them. #include <itkVersion.h>
bool myClass::myClassFuncion()
{
//get itk version
itk::Version whichItk;
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.
thanks.
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 ?
it should.
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 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 Version.